@momentum-design/components 0.85.5 → 0.85.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/browser/index.js +242 -218
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/menubar/menubar.component.d.ts +7 -1
  4. package/dist/components/menubar/menubar.component.js +37 -19
  5. package/dist/components/menuitem/menuitem.component.d.ts +21 -1
  6. package/dist/components/menuitem/menuitem.component.js +29 -1
  7. package/dist/components/menuitemcheckbox/menuitemcheckbox.component.d.ts +26 -15
  8. package/dist/components/menuitemcheckbox/menuitemcheckbox.component.js +42 -25
  9. package/dist/components/menuitemcheckbox/menuitemcheckbox.constants.d.ts +1 -1
  10. package/dist/components/menuitemcheckbox/menuitemcheckbox.constants.js +1 -2
  11. package/dist/components/menuitemcheckbox/menuitemcheckbox.styles.js +0 -6
  12. package/dist/components/menuitemradio/menuitemradio.component.d.ts +61 -12
  13. package/dist/components/menuitemradio/menuitemradio.component.js +125 -40
  14. package/dist/components/menuitemradio/menuitemradio.constants.d.ts +9 -1
  15. package/dist/components/menuitemradio/menuitemradio.constants.js +9 -1
  16. package/dist/components/menuitemradio/menuitemradio.styles.d.ts +2 -0
  17. package/dist/components/menuitemradio/menuitemradio.styles.js +7 -0
  18. package/dist/components/menuitemradio/menuitemradio.types.d.ts +4 -1
  19. package/dist/components/menupopover/menupopover.component.d.ts +6 -0
  20. package/dist/components/menupopover/menupopover.component.js +11 -3
  21. package/dist/components/menupopover/menupopover.styles.js +4 -0
  22. package/dist/components/menupopover/menupopover.types.d.ts +11 -0
  23. package/dist/components/menupopover/menupopover.types.js +1 -0
  24. package/dist/components/menupopover/menupopover.utils.d.ts +4 -2
  25. package/dist/components/menupopover/menupopover.utils.js +1 -1
  26. package/dist/components/menusection/menusection.component.d.ts +15 -2
  27. package/dist/components/menusection/menusection.component.js +55 -4
  28. package/dist/components/menusection/menusection.constants.d.ts +1 -5
  29. package/dist/components/menusection/menusection.constants.js +1 -5
  30. package/dist/components/menusection/menusection.styles.d.ts +2 -0
  31. package/dist/components/menusection/menusection.styles.js +11 -0
  32. package/dist/components/menusection/menusection.types.d.ts +7 -4
  33. package/dist/custom-elements.json +619 -295
  34. package/dist/index.d.ts +3 -1
  35. package/dist/react/menuitem/index.d.ts +12 -1
  36. package/dist/react/menuitem/index.js +12 -1
  37. package/dist/react/menuitemcheckbox/index.d.ts +18 -7
  38. package/dist/react/menuitemcheckbox/index.js +18 -7
  39. package/dist/react/menuitemradio/index.d.ts +25 -2
  40. package/dist/react/menuitemradio/index.js +25 -2
  41. package/dist/react/menupopover/index.d.ts +8 -0
  42. package/dist/react/menupopover/index.js +8 -0
  43. package/dist/react/menusection/index.d.ts +6 -1
  44. package/dist/react/menusection/index.js +5 -1
  45. package/dist/utils/types.d.ts +10 -0
  46. package/package.json +1 -1
@@ -26,7 +26,10 @@ import { Component } from '../../models';
26
26
  declare class MenuBar extends Component {
27
27
  constructor();
28
28
  connectedCallback(): void;
29
- menuItems: Array<HTMLElement>;
29
+ /**
30
+ * Returns all menuitem elements, including those nested inside menusection.
31
+ */
32
+ get menuItems(): Array<HTMLElement>;
30
33
  update(changedProperties: PropertyValues): void;
31
34
  firstUpdated(changedProperties: PropertyValues): void;
32
35
  /**
@@ -43,6 +46,9 @@ declare class MenuBar extends Component {
43
46
  private navigateToMenuItem;
44
47
  private showSubmenu;
45
48
  private getKeyWithDirectionFix;
49
+ /**
50
+ * Determines if a menuitem is a top-level menuitem (direct child of menubar or child of menusection whose parent is menubar)
51
+ */
46
52
  private isTopLevelMenuItem;
47
53
  private isNestedMenuItem;
48
54
  private closeAllMenuPopovers;
@@ -1,19 +1,9 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
1
  import { html } from 'lit';
11
- import { queryAssignedElements } from 'lit/decorators.js';
12
2
  import { Component } from '../../models';
13
3
  import { ROLE } from '../../utils/roles';
14
4
  import { POPOVER_PLACEMENT } from '../popover/popover.constants';
15
5
  import { TAG_NAME as MENUPOPOVER_TAGNAME } from '../menupopover/menupopover.constants';
16
- import { TAG_NAME as MENUITEM_TAGNAME } from '../menuitem/menuitem.constants';
6
+ import { TAG_NAME as MENUSECTION_TAGNAME } from '../menusection/menusection.constants';
17
7
  import { KEYS } from '../../utils/keys';
18
8
  import { popoverStack } from '../popover/popover.stack';
19
9
  import { DEFAULTS, TAG_NAME as MENUBAR_TAGNAME } from './menubar.constants';
@@ -51,6 +41,25 @@ class MenuBar extends Component {
51
41
  this.role = ROLE.MENUBAR;
52
42
  this.ariaOrientation = DEFAULTS.ORIENTATION;
53
43
  }
44
+ /**
45
+ * Returns all menuitem elements, including those nested inside menusection.
46
+ */
47
+ get menuItems() {
48
+ var _a, _b;
49
+ const slot = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot');
50
+ const assigned = (_b = slot === null || slot === void 0 ? void 0 : slot.assignedElements({ flatten: true })) !== null && _b !== void 0 ? _b : [];
51
+ const items = [];
52
+ const collect = (el) => {
53
+ if (el.role === ROLE.MENUITEM && !el.hasAttribute('disabled')) {
54
+ items.push(el);
55
+ }
56
+ else if (el.tagName.toLowerCase() === MENUSECTION_TAGNAME) {
57
+ Array.from(el.children).forEach(collect);
58
+ }
59
+ };
60
+ assigned.forEach(collect);
61
+ return items;
62
+ }
54
63
  update(changedProperties) {
55
64
  super.update(changedProperties);
56
65
  this.updatePopoverPlacement();
@@ -124,13 +133,26 @@ class MenuBar extends Component {
124
133
  return KEYS.ARROW_LEFT;
125
134
  return originalKey;
126
135
  }
136
+ /**
137
+ * Determines if a menuitem is a top-level menuitem (direct child of menubar or child of menusection whose parent is menubar)
138
+ */
127
139
  isTopLevelMenuItem(element) {
128
140
  var _a;
129
- return (((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) === MENUBAR_TAGNAME &&
130
- element.tagName.toLowerCase() === MENUITEM_TAGNAME);
141
+ const parent = element.parentElement;
142
+ if (!parent || element.role !== ROLE.MENUITEM)
143
+ return false;
144
+ const parentTag = parent.tagName.toLowerCase();
145
+ if (parentTag === MENUBAR_TAGNAME) {
146
+ return true;
147
+ }
148
+ if (parentTag === MENUSECTION_TAGNAME &&
149
+ ((_a = parent.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) === MENUBAR_TAGNAME) {
150
+ return true;
151
+ }
152
+ return false;
131
153
  }
132
154
  isNestedMenuItem(element) {
133
- return !!element.closest(MENUPOPOVER_TAGNAME) && element.tagName.toLowerCase() === MENUITEM_TAGNAME;
155
+ return !!element.closest(MENUPOPOVER_TAGNAME) && element.role === ROLE.MENUITEM;
134
156
  }
135
157
  async closeAllMenuPopovers() {
136
158
  const popovers = [];
@@ -144,7 +166,7 @@ class MenuBar extends Component {
144
166
  await Promise.all(popovers.map(popover => popover.updateComplete));
145
167
  }
146
168
  async crossMenubarNavigationOnLeft(element) {
147
- const isMenuItem = element.tagName.toLowerCase() === MENUITEM_TAGNAME;
169
+ const isMenuItem = element.role === ROLE.MENUITEM;
148
170
  if (isMenuItem) {
149
171
  const parentPopover = element.closest(MENUPOPOVER_TAGNAME);
150
172
  const triggerId = parentPopover === null || parentPopover === void 0 ? void 0 : parentPopover.getAttribute('triggerid');
@@ -229,8 +251,4 @@ class MenuBar extends Component {
229
251
  }
230
252
  }
231
253
  MenuBar.styles = [...Component.styles, ...styles];
232
- __decorate([
233
- queryAssignedElements({ selector: `${MENUITEM_TAGNAME}:not([disabled])` }),
234
- __metadata("design:type", Array)
235
- ], MenuBar.prototype, "menuItems", void 0);
236
254
  export default MenuBar;
@@ -8,7 +8,10 @@ import type { ArrowPositions, ArrowDirections } from './menuitem.types';
8
8
  * The leading and trailing slots can be used to display controls and text.<br/>
9
9
  * Based on the leading/trailing slot, the position of the controls and text can be adjusted.
10
10
  *
11
- * Please use mdc-menu as a parent element even when there is only menuitem for a11y purpose.
11
+ * Please use element with role=menu as a parent element even when there is only menuitem for a11y purpose.
12
+ * For example mdc-menupopover or mdc-menubar.
13
+ *
14
+ * Menu item has `name` and `value` attribute that can be used to identify the menu item when it is selected.
12
15
  *
13
16
  * @dependency mdc-text
14
17
  * @dependency mdc-icon
@@ -16,6 +19,14 @@ import type { ArrowPositions, ArrowDirections } from './menuitem.types';
16
19
  *
17
20
  * @tagname mdc-menuitem
18
21
  *
22
+ * @slot leading-controls - slot for menu item controls to appear of leading end.
23
+ * @slot leading-text-primary-label - slot for menu item primary label.
24
+ * @slot leading-text-secondary-label - slot for menu item secondary label.
25
+ * @slot leading-text-tertiary-label - slot for menu item tertiary label.
26
+ * @slot trailing-text-side-header - slot for menu item side header text.
27
+ * @slot trailing-text-subline - slot for menu item subline text.
28
+ * @slot trailing-controls - slot for menu item controls to appear of trailing end.
29
+ *
19
30
  * @event click - (React: onClick) This event is dispatched when the menuitem is clicked.
20
31
  * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the menuitem.
21
32
  * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the menuitem.
@@ -36,6 +47,15 @@ declare class MenuItem extends ListItem {
36
47
  * - `'negative'`: Arrow points toward the leading side.
37
48
  */
38
49
  arrowDirection?: ArrowDirections;
50
+ /**
51
+ * The name attribute is used to identify the menu item when it is selected.
52
+ */
53
+ name?: undefined | string;
54
+ /**
55
+ * The value attribute is used to represent a value when the menu item is selected.
56
+ * It is typically used with checkbox and radio menu items, but can be handy for any menu item.
57
+ */
58
+ value?: undefined | string;
39
59
  constructor();
40
60
  /**
41
61
  * Handles the keydown event for the menu item.
@@ -22,7 +22,10 @@ import styles from './menuitem.styles';
22
22
  * The leading and trailing slots can be used to display controls and text.<br/>
23
23
  * Based on the leading/trailing slot, the position of the controls and text can be adjusted.
24
24
  *
25
- * Please use mdc-menu as a parent element even when there is only menuitem for a11y purpose.
25
+ * Please use element with role=menu as a parent element even when there is only menuitem for a11y purpose.
26
+ * For example mdc-menupopover or mdc-menubar.
27
+ *
28
+ * Menu item has `name` and `value` attribute that can be used to identify the menu item when it is selected.
26
29
  *
27
30
  * @dependency mdc-text
28
31
  * @dependency mdc-icon
@@ -30,6 +33,14 @@ import styles from './menuitem.styles';
30
33
  *
31
34
  * @tagname mdc-menuitem
32
35
  *
36
+ * @slot leading-controls - slot for menu item controls to appear of leading end.
37
+ * @slot leading-text-primary-label - slot for menu item primary label.
38
+ * @slot leading-text-secondary-label - slot for menu item secondary label.
39
+ * @slot leading-text-tertiary-label - slot for menu item tertiary label.
40
+ * @slot trailing-text-side-header - slot for menu item side header text.
41
+ * @slot trailing-text-subline - slot for menu item subline text.
42
+ * @slot trailing-controls - slot for menu item controls to appear of trailing end.
43
+ *
33
44
  * @event click - (React: onClick) This event is dispatched when the menuitem is clicked.
34
45
  * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the menuitem.
35
46
  * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the menuitem.
@@ -38,6 +49,15 @@ import styles from './menuitem.styles';
38
49
  class MenuItem extends ListItem {
39
50
  constructor() {
40
51
  super();
52
+ /**
53
+ * The name attribute is used to identify the menu item when it is selected.
54
+ */
55
+ this.name = undefined;
56
+ /**
57
+ * The value attribute is used to represent a value when the menu item is selected.
58
+ * It is typically used with checkbox and radio menu items, but can be handy for any menu item.
59
+ */
60
+ this.value = undefined;
41
61
  this.addEventListener('keyup', this.handleKeyUp);
42
62
  }
43
63
  /**
@@ -116,4 +136,12 @@ __decorate([
116
136
  property({ type: String, reflect: true, attribute: 'arrow-direction' }),
117
137
  __metadata("design:type", String)
118
138
  ], MenuItem.prototype, "arrowDirection", void 0);
139
+ __decorate([
140
+ property({ type: String, reflect: true }),
141
+ __metadata("design:type", Object)
142
+ ], MenuItem.prototype, "name", void 0);
143
+ __decorate([
144
+ property({ type: String, reflect: true }),
145
+ __metadata("design:type", Object)
146
+ ], MenuItem.prototype, "value", void 0);
119
147
  export default MenuItem;
@@ -1,26 +1,30 @@
1
- import type { CSSResult, TemplateResult } from 'lit';
1
+ import type { PropertyValues, CSSResult, TemplateResult } from 'lit';
2
2
  import MenuItem from '../menuitem/menuitem.component';
3
- import type { AriaCheckedStates } from '../menusection/menusection.types';
4
3
  import type { Indicator } from './menuitemcheckbox.types';
5
4
  /**
6
5
  * A menuitemcheckbox component is a checkable menuitem.
7
6
  * There should be no focusable descendants inside this menuitemcheckbox component.
8
7
  *
9
- * The `aria-checked` attribute indicates whether the menuitemcheckbox is checked or not.
8
+ * The `checked` attribute indicates whether the menuitemcheckbox is checked or not.
10
9
  *
11
- * The `indicator` attribute is used to differentiate between <b>checkbox</b>, <b>checkmark</b> and <b>toggle</b>.
12
- * By default the `indicator` is set to <b>checkbox</b>.<br/>
10
+ * Menu item checkbox has `name` and `value` attribute that can be used to identify the menu item when it is selected.
11
+ *
12
+ * The `indicator` attribute is used to differentiate between <b>checkbox</b>, <b>checkmark</b>, <b>toggle</b> and <b>none</b>.
13
+ * By default, the `indicator` is set to <b>checkbox</b>.<br/>
13
14
  *
14
15
  * The checkbox will always be positioned on the leading side of the menuitem label and
15
16
  * the toggle and checkmark will always be positioned on the trailing side.
16
17
  *
17
18
  * The checkbox will have the possible states of `true` or `false`.
18
- * If the indicator is set to <b>checkmark</b> and if the `aria-checked` attribute is set to `true`,
19
+ * If the indicator is set to <b>checkmark</b> and if the `checked` attribute is set to `true`,
19
20
  * then the checkmark will be displayed. if not, then no indicator will be displayed.
20
21
  *
21
- * If you want only one item in a group to be checked, consider using menuitemradio component.
22
+ * The forth options for the `indicator` is <b>none</b>, which will not display any indicator at all.
23
+ * It is intended to be used for customised menu items where the indicator is implemented differently.
24
+ * For example, you can use a custom icon or a different visual element to indicate the state of the menu item.
25
+ * Make sure the new indicator is accessible.
22
26
  *
23
- * If a menuitemcheckbox is disabled, then the `aria-disabled` attribute is set to `true`.
27
+ * If you want only one item in a group to be checked, consider using menuitemradio component.
24
28
  *
25
29
  * @dependency mdc-staticcheckbox
26
30
  * @dependency mdc-statictoggle
@@ -28,7 +32,13 @@ import type { Indicator } from './menuitemcheckbox.types';
28
32
  *
29
33
  * @tagname mdc-menuitemcheckbox
30
34
  *
31
- * @cssproperty --mdc-checkmark-indicator-color - Allows customization of the checkmark indicator color
35
+ * @slot leading-controls - slot for menu item checkbox controls to appear of leading end.
36
+ * @slot leading-text-primary-label - slot for menu item checkbox primary label.
37
+ * @slot leading-text-secondary-label - slot for menu item checkbox secondary label.
38
+ * @slot leading-text-tertiary-label - slot for menu item checkbox tertiary label.
39
+ * @slot trailing-text-side-header - slot for menu item checkbox side header text.
40
+ * @slot trailing-text-subline - slot for menu item checkbox subline text.
41
+ * @slot trailing-controls - slot for menu item checkbox controls to appear of trailing end.
32
42
  *
33
43
  * @event change - (React: onChange) This event is dispatched when the menuitemcheckbox changes.
34
44
  * @event click - (React: onClick) This event is dispatched when the menuitemcheckbox is clicked.
@@ -36,10 +46,10 @@ import type { Indicator } from './menuitemcheckbox.types';
36
46
  */
37
47
  declare class MenuItemCheckbox extends MenuItem {
38
48
  /**
39
- * The aria-checked attribute is used to indicate that the menuitemcheckbox is checked or not.
40
- * @default 'false'
49
+ * The checked attribute is used to indicate that the menuitemcheckbox is checked or not.
50
+ * @default false
41
51
  */
42
- ariaChecked: AriaCheckedStates;
52
+ checked: boolean;
43
53
  /**
44
54
  * The indicator attribute is used to differentiate between <b>checkbox</b> and <b>toggle</b>.
45
55
  * @default 'checkbox'
@@ -50,9 +60,10 @@ declare class MenuItemCheckbox extends MenuItem {
50
60
  /**
51
61
  * Handles click events to toggle checked state
52
62
  * If the menuitemcheckbox is disabled, it does nothing.
53
- * If the menuitemcheckbox is not disabled, it toggles the `aria-checked` state between `true` and `false`.
63
+ * If the menuitemcheckbox is not disabled, it toggles the `checked` state between `true` and `false`.
54
64
  */
55
65
  private menuitemcheckboxHandleClick;
66
+ update(changedProperties: PropertyValues): void;
56
67
  /**
57
68
  * Returns a static checkbox element if the indicator is set to checkbox.
58
69
  * If the indicator is not set to checkbox, it returns nothing.
@@ -68,8 +79,8 @@ declare class MenuItemCheckbox extends MenuItem {
68
79
  */
69
80
  private staticToggle;
70
81
  /**
71
- * Returns a checkmark icon if the indicator is set to checkmark and the aria-checked state is true.
72
- * If the indicator is not set to checkmark or the aria-checked state is false, it returns nothing.
82
+ * Returns a checkmark icon if the indicator is set to checkmark and the checked state is true.
83
+ * If the indicator is not set to checkmark or the checked state is false, it returns nothing.
73
84
  *
74
85
  * The checkmark icon will always be positioned on the trailing side of the menuitem label.
75
86
  * @returns TemplateResult | typeof nothing
@@ -13,28 +13,32 @@ import { ROLE } from '../../utils/roles';
13
13
  import MenuItem from '../menuitem/menuitem.component';
14
14
  import { TYPE } from '../text/text.constants';
15
15
  import { TOGGLE_SIZE } from '../toggle/toggle.constants';
16
- import { ARIA_CHECKED_STATES } from '../menusection/menusection.constants';
17
16
  import { DEFAULTS, INDICATOR } from './menuitemcheckbox.constants';
18
17
  import styles from './menuitemcheckbox.styles';
19
18
  /**
20
19
  * A menuitemcheckbox component is a checkable menuitem.
21
20
  * There should be no focusable descendants inside this menuitemcheckbox component.
22
21
  *
23
- * The `aria-checked` attribute indicates whether the menuitemcheckbox is checked or not.
22
+ * The `checked` attribute indicates whether the menuitemcheckbox is checked or not.
24
23
  *
25
- * The `indicator` attribute is used to differentiate between <b>checkbox</b>, <b>checkmark</b> and <b>toggle</b>.
26
- * By default the `indicator` is set to <b>checkbox</b>.<br/>
24
+ * Menu item checkbox has `name` and `value` attribute that can be used to identify the menu item when it is selected.
25
+ *
26
+ * The `indicator` attribute is used to differentiate between <b>checkbox</b>, <b>checkmark</b>, <b>toggle</b> and <b>none</b>.
27
+ * By default, the `indicator` is set to <b>checkbox</b>.<br/>
27
28
  *
28
29
  * The checkbox will always be positioned on the leading side of the menuitem label and
29
30
  * the toggle and checkmark will always be positioned on the trailing side.
30
31
  *
31
32
  * The checkbox will have the possible states of `true` or `false`.
32
- * If the indicator is set to <b>checkmark</b> and if the `aria-checked` attribute is set to `true`,
33
+ * If the indicator is set to <b>checkmark</b> and if the `checked` attribute is set to `true`,
33
34
  * then the checkmark will be displayed. if not, then no indicator will be displayed.
34
35
  *
35
- * If you want only one item in a group to be checked, consider using menuitemradio component.
36
+ * The forth options for the `indicator` is <b>none</b>, which will not display any indicator at all.
37
+ * It is intended to be used for customised menu items where the indicator is implemented differently.
38
+ * For example, you can use a custom icon or a different visual element to indicate the state of the menu item.
39
+ * Make sure the new indicator is accessible.
36
40
  *
37
- * If a menuitemcheckbox is disabled, then the `aria-disabled` attribute is set to `true`.
41
+ * If you want only one item in a group to be checked, consider using menuitemradio component.
38
42
  *
39
43
  * @dependency mdc-staticcheckbox
40
44
  * @dependency mdc-statictoggle
@@ -42,7 +46,13 @@ import styles from './menuitemcheckbox.styles';
42
46
  *
43
47
  * @tagname mdc-menuitemcheckbox
44
48
  *
45
- * @cssproperty --mdc-checkmark-indicator-color - Allows customization of the checkmark indicator color
49
+ * @slot leading-controls - slot for menu item checkbox controls to appear of leading end.
50
+ * @slot leading-text-primary-label - slot for menu item checkbox primary label.
51
+ * @slot leading-text-secondary-label - slot for menu item checkbox secondary label.
52
+ * @slot leading-text-tertiary-label - slot for menu item checkbox tertiary label.
53
+ * @slot trailing-text-side-header - slot for menu item checkbox side header text.
54
+ * @slot trailing-text-subline - slot for menu item checkbox subline text.
55
+ * @slot trailing-controls - slot for menu item checkbox controls to appear of trailing end.
46
56
  *
47
57
  * @event change - (React: onChange) This event is dispatched when the menuitemcheckbox changes.
48
58
  * @event click - (React: onClick) This event is dispatched when the menuitemcheckbox is clicked.
@@ -52,10 +62,10 @@ class MenuItemCheckbox extends MenuItem {
52
62
  constructor() {
53
63
  super();
54
64
  /**
55
- * The aria-checked attribute is used to indicate that the menuitemcheckbox is checked or not.
56
- * @default 'false'
65
+ * The checked attribute is used to indicate that the menuitemcheckbox is checked or not.
66
+ * @default false
57
67
  */
58
- this.ariaChecked = DEFAULTS.ARIA_CHECKED;
68
+ this.checked = false;
59
69
  /**
60
70
  * The indicator attribute is used to differentiate between <b>checkbox</b> and <b>toggle</b>.
61
71
  * @default 'checkbox'
@@ -64,13 +74,14 @@ class MenuItemCheckbox extends MenuItem {
64
74
  /**
65
75
  * Handles click events to toggle checked state
66
76
  * If the menuitemcheckbox is disabled, it does nothing.
67
- * If the menuitemcheckbox is not disabled, it toggles the `aria-checked` state between `true` and `false`.
77
+ * If the menuitemcheckbox is not disabled, it toggles the `checked` state between `true` and `false`.
68
78
  */
69
- this.menuitemcheckboxHandleClick = () => {
79
+ this.menuitemcheckboxHandleClick = (event) => {
80
+ event.stopPropagation();
70
81
  if (this.disabled)
71
82
  return;
72
- const prevChecked = this.ariaChecked === ARIA_CHECKED_STATES.TRUE;
73
- this.ariaChecked = prevChecked ? ARIA_CHECKED_STATES.FALSE : ARIA_CHECKED_STATES.TRUE;
83
+ this.checked = !this.checked;
84
+ this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
74
85
  };
75
86
  this.addEventListener('click', this.menuitemcheckboxHandleClick);
76
87
  }
@@ -78,6 +89,12 @@ class MenuItemCheckbox extends MenuItem {
78
89
  super.connectedCallback();
79
90
  this.role = ROLE.MENUITEMCHECKBOX;
80
91
  }
92
+ update(changedProperties) {
93
+ super.update(changedProperties);
94
+ if (changedProperties.has('checked')) {
95
+ this.ariaChecked = `${this.checked}`;
96
+ }
97
+ }
81
98
  /**
82
99
  * Returns a static checkbox element if the indicator is set to checkbox.
83
100
  * If the indicator is not set to checkbox, it returns nothing.
@@ -90,7 +107,7 @@ class MenuItemCheckbox extends MenuItem {
90
107
  return html `
91
108
  <mdc-staticcheckbox
92
109
  slot="leading-controls"
93
- ?checked="${this.ariaChecked === ARIA_CHECKED_STATES.TRUE}"
110
+ ?checked="${this.checked}"
94
111
  ?disabled="${this.disabled}"
95
112
  ></mdc-staticcheckbox>
96
113
  `;
@@ -109,24 +126,24 @@ class MenuItemCheckbox extends MenuItem {
109
126
  return html `
110
127
  <mdc-statictoggle
111
128
  slot="trailing-controls"
112
- ?checked="${this.ariaChecked === ARIA_CHECKED_STATES.TRUE}"
129
+ ?checked="${this.checked}"
113
130
  ?disabled="${this.disabled}"
114
131
  size="${TOGGLE_SIZE.COMPACT}"
115
132
  ></mdc-statictoggle>
116
133
  `;
117
134
  }
118
135
  /**
119
- * Returns a checkmark icon if the indicator is set to checkmark and the aria-checked state is true.
120
- * If the indicator is not set to checkmark or the aria-checked state is false, it returns nothing.
136
+ * Returns a checkmark icon if the indicator is set to checkmark and the checked state is true.
137
+ * If the indicator is not set to checkmark or the checked state is false, it returns nothing.
121
138
  *
122
139
  * The checkmark icon will always be positioned on the trailing side of the menuitem label.
123
140
  * @returns TemplateResult | typeof nothing
124
141
  */
125
142
  getCheckmarkIcon() {
126
- if (this.indicator !== INDICATOR.CHECKMARK || this.ariaChecked === ARIA_CHECKED_STATES.FALSE) {
127
- return nothing;
143
+ if (this.checked && this.indicator === INDICATOR.CHECKMARK) {
144
+ return html ` <mdc-icon slot="trailing-controls" name="check-bold" part="checkmark-icon"></mdc-icon> `;
128
145
  }
129
- return html ` <mdc-icon slot="trailing-controls" name="check-bold" part="checkmark-icon"></mdc-icon> `;
146
+ return nothing;
130
147
  }
131
148
  render() {
132
149
  return html `
@@ -152,9 +169,9 @@ class MenuItemCheckbox extends MenuItem {
152
169
  }
153
170
  MenuItemCheckbox.styles = [...MenuItem.styles, ...styles];
154
171
  __decorate([
155
- property({ type: String, reflect: true, attribute: 'aria-checked' }),
156
- __metadata("design:type", String)
157
- ], MenuItemCheckbox.prototype, "ariaChecked", void 0);
172
+ property({ type: Boolean, reflect: true }),
173
+ __metadata("design:type", Boolean)
174
+ ], MenuItemCheckbox.prototype, "checked", void 0);
158
175
  __decorate([
159
176
  property({ type: String, reflect: true }),
160
177
  __metadata("design:type", String)
@@ -1,11 +1,11 @@
1
1
  declare const TAG_NAME: "mdc-menuitemcheckbox";
2
2
  declare const INDICATOR: {
3
+ readonly NONE: "none";
3
4
  readonly CHECKBOX: "checkbox";
4
5
  readonly CHECKMARK: "checkmark";
5
6
  readonly TOGGLE: "toggle";
6
7
  };
7
8
  declare const DEFAULTS: {
8
- readonly ARIA_CHECKED: "false";
9
9
  readonly INDICATOR: "checkbox";
10
10
  };
11
11
  export { TAG_NAME, INDICATOR, DEFAULTS };
@@ -1,13 +1,12 @@
1
1
  import utils from '../../utils/tag-name';
2
- import { ARIA_CHECKED_STATES } from '../menusection/menusection.constants';
3
2
  const TAG_NAME = utils.constructTagName('menuitemcheckbox');
4
3
  const INDICATOR = {
4
+ NONE: 'none',
5
5
  CHECKBOX: 'checkbox',
6
6
  CHECKMARK: 'checkmark',
7
7
  TOGGLE: 'toggle',
8
8
  };
9
9
  const DEFAULTS = {
10
- ARIA_CHECKED: ARIA_CHECKED_STATES.FALSE,
11
10
  INDICATOR: INDICATOR.CHECKBOX,
12
11
  };
13
12
  export { TAG_NAME, INDICATOR, DEFAULTS };
@@ -1,12 +1,6 @@
1
1
  import { css } from 'lit';
2
2
  const styles = css `
3
- :host {
4
- --mdc-checkmark-indicator-color: var(--mds-color-theme-control-active-normal);
5
- }
6
3
  :host::part(checkmark-icon) {
7
- --mdc-icon-fill-color: var(--mdc-checkmark-indicator-color);
8
- }
9
- :host([disabled])::part(checkmark-icon) {
10
4
  --mdc-icon-fill-color: currentColor;
11
5
  }
12
6
  `;
@@ -1,22 +1,45 @@
1
- import type { CSSResult } from 'lit';
1
+ import type { PropertyValues, CSSResult, TemplateResult } from 'lit';
2
2
  import MenuItem from '../menuitem/menuitem.component';
3
- import type { AriaCheckedStates } from '../menusection/menusection.types';
3
+ import { Indicator } from './menuitemradio.types';
4
4
  /**
5
5
  * A menuitemradio component is a checkable menuitem that is used in a menu.
6
6
  * A menuitemradio should be checked only one at a time. <br/>
7
7
  * There should be no focusable descendants inside this menuitemradio component.
8
8
  *
9
- * The `aria-checked` menuitemradio attribute is used to indicate that the menuitemradio is checked or not.
9
+ * The `checked` menuitemradio attribute is used to indicate that the menuitemradio is checked or not.
10
+ *
11
+ * Menu item radio has `name` and `value` attribute that can be used to identify the menu item when it is selected.
10
12
  *
11
13
  * If you want more than one item in a group to be checked, consider using menuitemcheckbox component.
12
14
  *
13
- * If a menuitemradio is disabled, then the `aria-disabled` attribute is set to `true`.
15
+ * The `indicator` attribute is used to differentiate between <b>radio</b>, <b>checkmark</b> and <b>none</b>.
16
+ * By default, the `indicator` is set to <b>radio</b>.<br/>
17
+ *
18
+ * The checkbox will always be positioned on the leading side of the menuitem label and
19
+ * the checkmark will always be positioned on the trailing side.
20
+ *
21
+ * The radio will have the possible states of `true` or `false`.
22
+ * If the indicator is set to <b>checkmark</b> and if the `checked` attribute is set to `true`,
23
+ * then the checkmark will be displayed. if not, then no indicator will be displayed.
24
+ *
25
+ * The third options for the `indicator` is <b>none</b>, which will not display any indicator at all.
26
+ * It is intended to be used for customised menu items where the indicator is implemented differently.
27
+ * For example, you can use a custom icon or a different visual element to indicate the state of the menu item.
28
+ * Make sure the new indicator is accessible.
14
29
  *
15
30
  * @dependency mdc-staticradio
16
31
  * @dependency mdc-text
17
32
  *
18
33
  * @tagname mdc-menuitemradio
19
34
  *
35
+ * @slot leading-controls - slot for menu item radio controls to appear of leading end.
36
+ * @slot leading-text-primary-label - slot for menu item radio primary label.
37
+ * @slot leading-text-secondary-label - slot for menu item radio secondary label.
38
+ * @slot leading-text-tertiary-label - slot for menu item radio tertiary label.
39
+ * @slot trailing-text-side-header - slot for menu item radio side header text.
40
+ * @slot trailing-text-subline - slot for menu item radio subline text.
41
+ * @slot trailing-controls - slot for menu item radio controls to appear of trailing end.
42
+ *
20
43
  * @event change - (React: onChange) This event is dispatched when the menuitemradio changes.
21
44
  * @event click - (React: onClick) This event is dispatched when the menuitemradio is clicked.
22
45
  * @event focus - (React: onFocus) This event is dispatched when the menuitemradio receives focus.
@@ -24,22 +47,48 @@ import type { AriaCheckedStates } from '../menusection/menusection.types';
24
47
  declare class MenuItemRadio extends MenuItem {
25
48
  /**
26
49
  * The aria-checked attribute is used to indicate that the menuitemradio is checked or not.
27
- * @default 'false'
50
+ * @default false
28
51
  */
29
- ariaChecked: AriaCheckedStates;
52
+ checked: boolean;
30
53
  /**
31
- * The name attribute is used to group radio items within the same menu container.
54
+ * The indicator attribute is used to differentiate between <b>radio</b>, <b>checkmark</b> and <b>none</b>.
55
+ * @default 'radio'
32
56
  */
33
- name: string;
57
+ indicator: Indicator;
34
58
  constructor();
35
59
  connectedCallback(): void;
60
+ /**
61
+ * Returns all radios within the same group (name).
62
+ */
63
+ private getAllRadiosWithinSameGroup;
64
+ /**
65
+ * Updates the checked state of all other radios in the same group.
66
+ * This method is called when a radio is clicked to ensure that only one radio in the group can be checked at a time.
67
+ * It sets the `checked` property of all other radios in the same group to `false`.
68
+ */
69
+ private updateOtherRadiosCheckedState;
36
70
  /**
37
71
  * Handles click events to set checked state and uncheck siblings in the same group and container.
38
- * If the menuitemradio is not checked, it sets its aria-checked state to `true`
39
- * and sets all other menuitemradio elements of the same group with aria-checked state to `false`.
72
+ * If the menuitemradio is not checked, it sets its checked state to `true`
73
+ * and sets all other menuitemradio elements of the same group with checked state to `false`.
74
+ */
75
+ private radioHandleClick;
76
+ update(changedProperties: PropertyValues): void;
77
+ /**
78
+ * Returns a static checkbox element if the indicator is set to checkbox.
79
+ * If the indicator is not set to checkbox, it returns nothing.
80
+ * @returns TemplateResult | typeof nothing
81
+ */
82
+ private renderStaticRadio;
83
+ /**
84
+ * Returns a checkmark icon if the indicator is set to checkmark and the checked state is true.
85
+ * If the indicator is not set to checkmark or the checked state is false, it returns nothing.
86
+ *
87
+ * The checkmark icon will always be positioned on the trailing side of the menuitem label.
88
+ * @returns TemplateResult | typeof nothing
40
89
  */
41
- private menuitemradioHandleClick;
42
- render(): import("lit-html").TemplateResult<1>;
90
+ private renderCheckmarkIcon;
91
+ render(): TemplateResult<1>;
43
92
  static styles: Array<CSSResult>;
44
93
  }
45
94
  export default MenuItemRadio;