Skip to content

Commit d8c7bbb

Browse files
authored
feat: navigation components allow composition (#242)
* update menu style * wip update styles for main nav and nav link * clean up * rename parseItems to parseJsonProp * clean up function update * update current link style * data driven nav link * rename go-main-nav to go-nav-bar * refactor go-nav-bar into go-nav-item * nav item add columns option * add columns option to nav item object * refactor go-nav-item, go-nav-submenu-trigger and go-nav-submenu to allow composability * header slot check * footer update * fix nav list in footer * update go-nav-bar examples
1 parent b144eca commit d8c7bbb

40 files changed

+1552
-1056
lines changed

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"clean": "rm -rf dist",
2020
"build": "pnpm run clean && stencil build",
2121
"build.component-docs": "stencil build --docs-readme --docs-json",
22-
"start": "stencil build --dev --watch --serve",
22+
"start": "pnpm run clean && stencil build --dev --watch --serve",
2323
"watch.components": "stencil build --docs-json --watch",
2424
"test.spec": "stencil test --spec",
2525
"test.spec.watch": "stencil test --spec --watchAll",

packages/core/src/components.d.ts

+145-91
Large diffs are not rendered by default.

packages/core/src/components/form/go-datepicker/go-datepicker.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, h, Prop, Element, State, Watch, EventEmitter, Event } from '@stencil/core';
22
import { uniqueId } from 'lodash-es';
33
import '@duetds/date-picker';
4-
import { fieldSlotNames, loadFieldProps, loadFieldSlots, parseItems } from '../../../utils';
4+
import { fieldSlotNames, loadFieldProps, loadFieldSlots, parseJsonProp } from '../../../utils';
55
import { FormFieldProps, GoChangeEventDetail } from '../../../interfaces';
66
import { DuetDatePickerProps } from './duet-date-picker';
77
import dayjs from 'dayjs';
@@ -56,7 +56,7 @@ export class GoDatepicker implements FormFieldProps {
5656

5757
@Watch('options')
5858
loadOptions() {
59-
this.parsedOptions = parseItems(this.options);
59+
this.parsedOptions = parseJsonProp(this.options);
6060
const dateFormat = this.format;
6161
this.parsedOptions = {
6262
...this.parsedOptions,

packages/core/src/components/form/go-select/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { SelectOption } from '@/interfaces';
7-
import { parseItems } from '@/utils';
7+
import { parseJsonProp } from '@/utils';
88

99
export enum Keys {
1010
Backspace = 'Backspace',
@@ -190,7 +190,7 @@ export const parseSelectOptions = (options: string | string[] | SelectOption[]):
190190
options = options.split(',');
191191
}
192192

193-
const parsedOptions = parseItems<SelectOption[] | string[]>(options);
193+
const parsedOptions = parseJsonProp<SelectOption[] | string[]>(options);
194194
if (parsedOptions) {
195195
// format parsed options into SelectOption[]
196196
return parsedOptions.map((option) =>

packages/core/src/components/go-breadcrumbs/go-breadcrumbs.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Host, h, Element, Prop, State, Watch } from '@stencil/core';
22
import { INavItem } from '../../interfaces';
3-
import { parseItems } from '../../utils';
3+
import { parseJsonProp } from '../../utils';
44

55
@Component({
66
tag: 'go-breadcrumbs',
@@ -38,7 +38,7 @@ export class GoBreadcrumb {
3838
}
3939

4040
getItems(items: INavItem[] | string) {
41-
const navItems = parseItems(items);
41+
const navItems = parseJsonProp(items);
4242
if (!this.hideCurrent) {
4343
return navItems;
4444
}

packages/core/src/components/go-dropdown-menu/readme.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,43 @@ title: Dropdown menu
1212

1313
::: info
1414

15-
For a list of navigational items, please refer to the following components:
16-
- [Main navigation](/docs/components/navigation/go-main-nav)
17-
- [Nav drawer](/docs/components/navigation/go-nav-drawer)
15+
For a list of navigational items, please refer to the following components:
16+
17+
- [Nav bar](/docs/components/navigation/go-nav-bar)
18+
- [Nav drawer](/docs/components/navigation/go-nav-drawer)
1819

1920
:::
2021

2122
## Trigger button
2223

2324
A dropdown menu requires a trigger element, this can be set by using `trigger-selector` similar to [`go-dropdown`](go-dropdown).
2425

25-
2626
## Persistent
2727

2828
A dropdown menu can be `persistent` in order to allow users to interact with the widget continuously.
2929

30-
3130
## Accessibility
3231

3332
WAI [Menu button](https://www.w3.org/WAI/ARIA/apg/patterns/menubutton/) pattern aligns closely to the `go-dropdown-menu` component.
3433

3534
### Menu button
35+
3636
- Use a button element (`go-button`, `button` or `input type="button"`) as the trigger element.
3737
- `aria-haspopup` will be set automatically on the trigger element to the id of the menu.
3838
- When the menu is displayed, the trigger element has `aria-expanded` set to true. When the menu is hidden, `aria-expanded` is removed. If `aria-expanded` is specified when the menu is hidden, it is set to false.
3939
- The trigger element has a value specified for `aria-controls` that refers to the element with role menu.
4040

41-
4241
#### Keyboard
42+
4343
When trigger button has focus:
44+
4445
- <kbd>Enter</kbd>: opens the menu and places focus on the first menu item.
4546
- <kbd>Space</kbd>: opens the menu and places focus on the first menu item.
4647
- <kbd>Down Arrow</kbd>: opens the menu and moves focus to the first menu item.
4748
- <kbd>Up Arrow</kbd>: opens the menu and moves focus to the last menu item.
4849

4950
When focus is inside the dropdown menu:
51+
5052
- <kbd>Down Arrow</kbd>: move focus to the next menu item, if current item is the last one, move focus to the first menu item.
5153
- <kbd>Up Arrow</kbd>: move focus to the previous menu item, if current item is the first one, move focus to the last menu item.
5254
- <kbd>Esc</kbd>: closes the menu.
@@ -56,10 +58,9 @@ When focus is inside the dropdown menu:
5658
The keyboard interaction of the menu follows the WAI guideline for [Keyboard navigation inside components](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_general_within), which means <kbd>Tab</kbd> and <kbd>Shift + Tab</kbd> do not move focus between menu items, instead, they are only used to focus in and out of the dropdown menu.
5759

5860
> the tab sequence should include only one focusable element of a composite UI component. Once a composite contains focus, keys other than <kbd>Tab</kbd> and <kbd>Shift + Tab</kbd> enable the user to move focus among its focusable elements
61+
>
5962
> - [Developing a Keyboard Interface](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_general_within) by WAI APG
6063
61-
62-
6364
## Demo
6465

6566
<demo-frame component="go-dropdown-menu" demo="go-dropdown-menu"></demo-frame>

packages/core/src/components/go-dropdown/go-dropdown.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, Host, h, Element, Prop, Method, Watch, Event, EventEmitter } from '@stencil/core';
22
import { uniqueId, debounce } from 'lodash-es';
33
import { computePosition, offset, flip, autoUpdate } from '@floating-ui/dom';
4-
import { onClickOutside, removeClickOutsideListener } from '../../utils';
4+
import { onClickOutside } from '../../utils';
55

66
@Component({
77
tag: 'go-dropdown',
@@ -105,7 +105,7 @@ export class GoDropdown {
105105

106106
private escapeHandler;
107107
private focusOutHandler;
108-
private clickOutHandler;
108+
private clickOutsideCleanUp;
109109

110110
async componentDidLoad() {
111111
if (!this.triggerEl) {
@@ -139,8 +139,8 @@ export class GoDropdown {
139139
if (this.focusOutHandler) {
140140
this.el.removeEventListener('focusout', this.focusOutHandler);
141141
}
142-
if (this.clickOutHandler) {
143-
removeClickOutsideListener(this.clickOutHandler);
142+
if (this.clickOutsideCleanUp) {
143+
this.clickOutsideCleanUp();
144144
}
145145
if (this.cleanupAutoUpdate) {
146146
this.cleanupAutoUpdate();
@@ -157,7 +157,7 @@ export class GoDropdown {
157157
this.triggerEl.addEventListener('click', () => this.toggle());
158158
}
159159

160-
this.clickOutHandler = onClickOutside(this.el, (e) => {
160+
this.clickOutsideCleanUp = onClickOutside(this.el, (e) => {
161161
if (!this.triggerEl.contains(e.target as Node) && this.isActive) {
162162
this.close();
163163
}

packages/core/src/components/go-icon/go-icon.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Component, Host, h, Element, Prop } from '@stencil/core';
22
import { IconProps } from '../../interfaces';
3-
import { inheritAttributes } from '../../utils/helper';
4-
export type MaterialIconVariants = `material-icons` | `material-icons-outlined` | `material-icons-round` | `material-icons-sharp`;
3+
import { $attrs } from '../../utils/helper';
4+
export type MaterialIconVariants =
5+
| `material-icons`
6+
| `material-icons-outlined`
7+
| `material-icons-round`
8+
| `material-icons-sharp`;
59
/**
610
* https://fontawesome.com/v5.15/how-to-use/on-the-web/referencing-icons/basic-use
711
*/
@@ -48,7 +52,7 @@ export class GoIcon implements IconProps {
4852

4953
private attrs = {} as any;
5054
componentWillLoad() {
51-
this.attrs = inheritAttributes(this.el, [], false);
55+
this.attrs = $attrs.bind(this)(false);
5256
}
5357

5458
render() {

packages/core/src/components/go-tabs/go-tablist.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ go-tablist {
4141
/**
4242
@prop --tab-active-color:
4343
Text color for active tab
44-
- default: var(--go-color-primary-800)
44+
- default: var(--go-color-primary-600)
4545
*/
4646
--tab-active-color: var(--go-color-primary-600);
4747
/**

0 commit comments

Comments
 (0)