@aiaiai-pt/design-system 0.55.1 → 0.55.2

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.
@@ -46,14 +46,21 @@
46
46
  let typeaheadBuffer = $state('');
47
47
  let typeaheadTimer = $state(0);
48
48
 
49
+ /** Every WAI-ARIA menu item role: plain, radio and checkbox items. */
50
+ const ITEM_ROLES = ['menuitem', 'menuitemradio', 'menuitemcheckbox'];
51
+ const ITEM_SELECTOR = ITEM_ROLES.map((r) => `[role="${r}"]`).join(', ');
52
+
49
53
  /**
50
- * Get all enabled menu items inside the menu container.
54
+ * Get all enabled menu items (any item role) inside the menu container.
55
+ * Skips items that are aria-disabled or natively :disabled.
51
56
  * @returns {HTMLElement[]}
52
57
  */
53
58
  function getItems() {
54
59
  if (!menuEl) return [];
55
60
  return /** @type {HTMLElement[]} */ (
56
- Array.from(menuEl.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])'))
61
+ Array.from(menuEl.querySelectorAll(ITEM_SELECTOR)).filter(
62
+ (el) => !el.matches(':disabled, [aria-disabled="true"]')
63
+ )
57
64
  );
58
65
  }
59
66
 
@@ -101,7 +108,7 @@
101
108
  case 'Enter':
102
109
  case ' ': {
103
110
  e.preventDefault();
104
- if (current && current.getAttribute('role') === 'menuitem') {
111
+ if (current && ITEM_ROLES.includes(current.getAttribute('role') ?? '')) {
105
112
  current.click();
106
113
  }
107
114
  break;
@@ -3,6 +3,8 @@
3
3
 
4
4
  A single actionable row inside a Menu.
5
5
  Renders as <button role="menuitem"> with optional leading/trailing snippets.
6
+ Set role="menuitemradio" or role="menuitemcheckbox" with `checked` for
7
+ selectable items; aria-checked is rendered only for those two roles.
6
8
 
7
9
  Consumes --menu-item-* tokens from components.css.
8
10
 
@@ -18,6 +20,11 @@
18
20
  Delete
19
21
  </MenuItem>
20
22
 
23
+ @example Radio item
24
+ <MenuItem role="menuitemradio" checked={sort === 'name'} onclick={() => (sort = 'name')}>
25
+ Sort by name
26
+ </MenuItem>
27
+
21
28
  @example With keyboard shortcut
22
29
  <MenuItem onclick={handleCopy}>
23
30
  Copy
@@ -25,9 +32,29 @@
25
32
  </MenuItem>
26
33
  -->
27
34
  <script>
35
+ /**
36
+ * @typedef {'menuitem' | 'menuitemradio' | 'menuitemcheckbox'} MenuItemRole
37
+ * @typedef {{
38
+ * variant?: string,
39
+ * role?: MenuItemRole,
40
+ * checked?: boolean,
41
+ * disabled?: boolean,
42
+ * leading?: import('svelte').Snippet,
43
+ * trailing?: import('svelte').Snippet,
44
+ * children?: import('svelte').Snippet,
45
+ * class?: string,
46
+ * [key: string]: unknown,
47
+ * }} Props
48
+ */
49
+
50
+ /** @type {Props} */
28
51
  let {
29
52
  /** @type {'default' | 'destructive'} */
30
53
  variant = 'default',
54
+ /** @type {MenuItemRole} */
55
+ role = 'menuitem',
56
+ /** Checked state; rendered as aria-checked only for menuitemradio/menuitemcheckbox. @type {boolean} */
57
+ checked = false,
31
58
  /** @type {boolean} */
32
59
  disabled = false,
33
60
  /** @type {import('svelte').Snippet | undefined} */
@@ -40,10 +67,15 @@
40
67
  class: className = '',
41
68
  ...rest
42
69
  } = $props();
70
+
71
+ const ariaChecked = $derived(
72
+ role === 'menuitemradio' || role === 'menuitemcheckbox' ? (checked ? 'true' : 'false') : undefined
73
+ );
43
74
  </script>
44
75
 
45
76
  <button
46
- role="menuitem"
77
+ {role}
78
+ aria-checked={ariaChecked}
47
79
  class="menu-item menu-item-{variant} {className}"
48
80
  class:menu-item-disabled={disabled}
49
81
  disabled={disabled || undefined}
@@ -1,13 +1,15 @@
1
1
  export default MenuItem;
2
2
  type MenuItem = {
3
3
  $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<$$ComponentProps>): void;
4
+ $set?(props: Partial<Props>): void;
5
5
  };
6
6
  /**
7
7
  * MenuItem
8
8
  *
9
9
  * A single actionable row inside a Menu.
10
10
  * Renders as <button role="menuitem"> with optional leading/trailing snippets.
11
+ * Set role="menuitemradio" or role="menuitemcheckbox" with `checked` for
12
+ * selectable items; aria-checked is rendered only for those two roles.
11
13
  *
12
14
  * Consumes --menu-item-* tokens from components.css.
13
15
  *
@@ -23,6 +25,11 @@ type MenuItem = {
23
25
  * Delete
24
26
  * </MenuItem>
25
27
  *
28
+ * @example Radio item
29
+ * <MenuItem role="menuitemradio" checked={sort === 'name'} onclick={() => (sort = 'name')}>
30
+ * Sort by name
31
+ * </MenuItem>
32
+ *
26
33
  * @example With keyboard shortcut
27
34
  * <MenuItem onclick={handleCopy}>
28
35
  * Copy
@@ -30,18 +37,24 @@ type MenuItem = {
30
37
  * </MenuItem>
31
38
  */
32
39
  declare const MenuItem: import("svelte").Component<{
40
+ [key: string]: unknown;
33
41
  variant?: string;
42
+ role?: "menuitem" | "menuitemradio" | "menuitemcheckbox";
43
+ checked?: boolean;
34
44
  disabled?: boolean;
35
- leading?: any;
36
- trailing?: any;
37
- children?: any;
45
+ leading?: import("svelte").Snippet;
46
+ trailing?: import("svelte").Snippet;
47
+ children?: import("svelte").Snippet;
38
48
  class?: string;
39
- } & Record<string, any>, {}, "">;
40
- type $$ComponentProps = {
49
+ }, {}, "">;
50
+ type Props = {
41
51
  variant?: string;
52
+ role?: "menuitem" | "menuitemradio" | "menuitemcheckbox";
53
+ checked?: boolean;
42
54
  disabled?: boolean;
43
- leading?: any;
44
- trailing?: any;
45
- children?: any;
55
+ leading?: import("svelte").Snippet;
56
+ trailing?: import("svelte").Snippet;
57
+ children?: import("svelte").Snippet;
46
58
  class?: string;
47
- } & Record<string, any>;
59
+ [key: string]: unknown;
60
+ };
@@ -99,11 +99,15 @@
99
99
  /** @type {HTMLElement | null} */
100
100
  const previouslyFocused = /** @type {HTMLElement | null} */ (document.activeElement);
101
101
 
102
- // Focus first focusable child
102
+ // Focus the first focusable child that is enabled (not :disabled and not
103
+ // aria-disabled). With none, leave focus where it is.
103
104
  requestAnimationFrame(() => {
104
- const focusable = popoverEl?.querySelector(
105
- 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
106
- );
105
+ if (!popoverEl) return;
106
+ const focusable = Array.from(
107
+ popoverEl.querySelectorAll(
108
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
109
+ )
110
+ ).find((el) => !el.matches(':disabled, [aria-disabled="true"]'));
107
111
  if (focusable) /** @type {HTMLElement} */ (focusable).focus();
108
112
  });
109
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/design-system",
3
- "version": "0.55.1",
3
+ "version": "0.55.2",
4
4
  "description": "Design system tokens and Svelte components for aiaiai products",
5
5
  "license": "MIT",
6
6
  "type": "module",