@tangible/ui 0.2.26 → 0.2.27

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.
@@ -12,6 +12,12 @@ import { defaultNavMenuLabels } from './types.js';
12
12
  // A panel opens when the pointer settles, not after a fixed delay; once the
13
13
  // bar is warm (a panel open, or one closed within PRIMED_WINDOW) the next
14
14
  // opens at once.
15
+ const INTERACTIVE = [
16
+ 'a[href]', 'area[href]', 'button', 'input:not([type=hidden])', 'select', 'textarea', 'summary',
17
+ 'iframe', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable=false])',
18
+ '[tabindex]:not([tabindex="-1"])', '[role=button]', '[role=link]', '[role=checkbox]', '[role=switch]',
19
+ '[role=menuitem]', '[role=tab]', '[aria-haspopup]',
20
+ ].join(', ');
15
21
  const PRIMED_WINDOW = 400;
16
22
  // Grace period for crossing into the panel.
17
23
  const HOVER_CLOSE_DELAY = 300;
@@ -93,7 +99,7 @@ function toAriaCurrent(current) {
93
99
  }
94
100
  const isSub = (node) => isValidElement(node) && node.type === NavMenuSub;
95
101
  const NavMenuItem = forwardRef(function NavMenuItem(props, ref) {
96
- const { current, icon, disabled, asChild, className, children, ...rest } = props;
102
+ const { current, icon, prefix, suffix, disabled, asChild, className, children, ...rest } = props;
97
103
  const inList = useContext(ListContext);
98
104
  const { orientation, flyoutTrigger, labels, openId, setOpenId, rootRef, warmth } = useContext(RootContext);
99
105
  const inFlyout = useContext(FlyoutContext);
@@ -104,6 +110,31 @@ const NavMenuItem = forwardRef(function NavMenuItem(props, ref) {
104
110
  console.warn('NavMenu.Item renders an <li>: place it inside NavMenu.Group or NavMenu.Sub.');
105
111
  }
106
112
  }, [inList]);
113
+ // The slots render inside the row's <a>/<button>, where interactive content
114
+ // is invalid HTML and unreachable for keyboard users.
115
+ const prefixRef = useRef(null);
116
+ const suffixRef = useRef(null);
117
+ const slotWarned = useRef({ both: false, interactive: false, named: false });
118
+ const restProps = rest;
119
+ const hasSlot = prefix != null || suffix != null;
120
+ const namedOver = hasSlot && (restProps['aria-label'] != null || restProps['aria-labelledby'] != null);
121
+ useEffect(() => {
122
+ if (!isDev())
123
+ return;
124
+ const w = slotWarned.current;
125
+ if (!w.both && prefix != null && icon) {
126
+ w.both = true;
127
+ console.warn('NavMenu.Item: `prefix` replaces `icon`; pass one or the other.');
128
+ }
129
+ if (!w.named && namedOver) {
130
+ w.named = true;
131
+ console.warn('NavMenu.Item: `aria-label`/`aria-labelledby` replaces the whole accessible name, so the `prefix`/`suffix` text is never announced. Let the row be named by its content.');
132
+ }
133
+ if (!w.interactive && [prefixRef.current, suffixRef.current].some((slot) => slot?.querySelector(INTERACTIVE))) {
134
+ w.interactive = true;
135
+ console.warn('NavMenu.Item: `prefix`/`suffix` render inside the row link, so they must not contain interactive content (links, buttons, inputs, tabindex).');
136
+ }
137
+ });
107
138
  // Sub lists render after the link, inside the same <li>.
108
139
  const all = Children.toArray(children);
109
140
  const subs = all.filter(isSub);
@@ -313,8 +344,11 @@ const NavMenuItem = forwardRef(function NavMenuItem(props, ref) {
313
344
  // Top-level rows of a bar. Rows inside a flyout panel keep the vertical look.
314
345
  const bar = orientation === 'horizontal' && !inFlyout;
315
346
  const itemClass = cx('tui-nav-menu__item', bar && 'is-bar', className);
316
- const iconNode = icon ? (_jsx("span", { className: "tui-nav-menu__icon", "aria-hidden": "true", children: _jsx(Icon, { name: icon }) })) : null;
317
- const content = (inner) => (_jsxs(_Fragment, { children: [iconNode, _jsx("span", { className: "tui-nav-menu__label", id: flyout ? labelId : undefined, children: inner })] }));
347
+ const leading = prefix != null ? (_jsx("span", { className: "tui-nav-menu__prefix", ref: prefixRef, children: prefix })) : icon ? (_jsx("span", { className: "tui-nav-menu__icon", "aria-hidden": "true", children: _jsx(Icon, { name: icon }) })) : null;
348
+ // The ' ' text nodes keep the slots as separate words in the accessible
349
+ // name ("Inbox 3 unread", not "Inbox3 unread"). A flex container doesn't
350
+ // render whitespace-only text, so layout is unaffected.
351
+ const content = (inner) => (_jsxs(_Fragment, { children: [leading, leading && prefix != null && ' ', _jsx("span", { className: "tui-nav-menu__label", id: flyout ? labelId : undefined, children: inner }), suffix != null && (_jsxs(_Fragment, { children: [' ', _jsx("span", { className: "tui-nav-menu__suffix", ref: suffixRef, children: suffix })] }))] }));
318
352
  const chevron = (_jsx("span", { className: "tui-nav-menu__chevron", "aria-hidden": "true", children: _jsx(Icon, { name: "system/chevron-down-small" }) }));
319
353
  let row;
320
354
  // A flyout parent with no destination of its own: the row IS the toggle.
@@ -73,6 +73,28 @@ type NavMenuItemBaseProps = {
73
73
  current?: NavMenuCurrent;
74
74
  /** Leading icon, from the registry. Sized by `--tui-nav-menu-icon-size`. */
75
75
  icon?: IconName;
76
+ /**
77
+ * Custom leading content in the icon's place (an avatar, a glyph not in the
78
+ * registry). Replaces `icon` when both are set. Unlike `icon`, it isn't
79
+ * hidden from assistive tech: mark decorative content `aria-hidden`
80
+ * yourself, or its text joins the name. A shape drawn with CSS `background`
81
+ * disappears in forced colors; give it a border if it carries meaning.
82
+ */
83
+ prefix?: ReactNode;
84
+ /**
85
+ * Trailing content pushed to the row's inline end: a badge, a count. It sits
86
+ * inside the row, so its text joins the accessible name: give a bare number
87
+ * context, so `3 <span class="tui-visually-hidden">unread</span>` reads
88
+ * "Inbox 3 unread" (put the space outside the hidden span). Must not be
89
+ * interactive (no buttons or links): a control nested in a link is invalid.
90
+ *
91
+ * Both slots reach the name only through the row's content, so don't pass
92
+ * `aria-label`/`aria-labelledby` to an item with a slot: either replaces
93
+ * the whole name. On a row that is itself the flyout's disclosure button,
94
+ * the suffix is part of the button's name; on a split row it belongs to the
95
+ * link (the destination), and the toggle stays "Reports submenu".
96
+ */
97
+ suffix?: ReactNode;
76
98
  /**
77
99
  * Inert item: rendered as a disabled link (`role="link"`, `aria-disabled`,
78
100
  * no href), out of the tab order. For destinations that exist but aren't
@@ -91,12 +113,12 @@ type NavMenuItemBaseProps = {
91
113
  children: ReactNode;
92
114
  };
93
115
  /** Link item: renders an `<a>`. */
94
- export type NavMenuItemAsLink = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'a'>, 'children' | 'aria-current'> & {
116
+ export type NavMenuItemAsLink = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'a'>, 'children' | 'aria-current' | 'prefix'> & {
95
117
  href: string;
96
118
  asChild?: never;
97
119
  };
98
120
  /** Action item: renders a `<button type="button">`. */
99
- export type NavMenuItemAsButton = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'button'>, 'children' | 'aria-current' | 'disabled'> & {
121
+ export type NavMenuItemAsButton = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'button'>, 'children' | 'aria-current' | 'prefix' | 'disabled'> & {
100
122
  href?: never;
101
123
  asChild?: never;
102
124
  };
@@ -105,7 +127,7 @@ export type NavMenuItemAsButton = NavMenuItemBaseProps & Omit<ComponentPropsWith
105
127
  * `<Link>`, say). It receives the item's class, `aria-current`, the icon and
106
128
  * a label wrapper. It must render a real `<a href>`.
107
129
  */
108
- export type NavMenuItemAsChild = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'a'>, 'children' | 'aria-current' | 'href'> & {
130
+ export type NavMenuItemAsChild = NavMenuItemBaseProps & Omit<ComponentPropsWithoutRef<'a'>, 'children' | 'aria-current' | 'prefix' | 'href'> & {
109
131
  asChild: true;
110
132
  href?: never;
111
133
  };
package/figma-tokens.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.26",
2
+ "version": "0.2.27",
3
3
  "source": "publish/styles/all.expanded.css",
4
4
  "prefix": "tui-",
5
5
  "note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation. CONTRACT: consumers read TUI defaults from this file at build time (variables[].cssVar, the \"Light\"/\"Dark\" mode names, and alias chains into TUI/Primitives). Renaming a cssVar or a mode is a breaking change to those consumers even when the CSS value is unchanged — a rename silently becomes an undefined default downstream — so treat it as at least a minor bump and call it out in the CHANGELOG.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
4
4
  "description": "Tangible Design System",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",
@@ -399,7 +399,7 @@ synthesise a second toggle. For a second control that toggles the same item (an
399
399
  ## Component names, and what isn't there
400
400
 
401
401
  46 components. If you are hunting for a name: **Alert → `Notice`**, **Menu → `Dropdown`**,
402
- **Table → `DataTable`**, **Pagination → `Pager`**, **Drawer → `Sidebar`** (drawer mode), **Nav menu / sidebar links / top nav bar → `NavMenu`** (inside `Sidebar.Nav` or your `<nav>`; `asChild` for router links, `current` for `aria-current`; `orientation="horizontal"` for a bar whose items open flyouts, `flyoutTrigger="hover"` to also open on mouse hover — don't hand-roll menus with `role="menu"`),
402
+ **Table → `DataTable`**, **Pagination → `Pager`**, **Drawer → `Sidebar`** (drawer mode), **Nav menu / sidebar links / top nav bar → `NavMenu`** (inside `Sidebar.Nav` or your `<nav>`; `asChild` for router links, `current` for `aria-current`; `orientation="horizontal"` for a bar whose items open flyouts, `flyoutTrigger="hover"` to also open on mouse hover; `suffix` for a row badge/count — a `Chip`, with visually hidden context for bare numbers, never interactive; row states restyle via `--tui-nav-menu-item-*`, per level via `--tui-nav-menu-{sub,bar,flyout}-item-*` — set `bar-item-*` for a dark header so flyout rows keep the panel's colours; don't hand-roll menus with `role="menu"`),
403
403
  **Badge → `Chip`** or `ContentIndicator`, **Spinner → `Progress`** or `Button loading`,
404
404
  **ConfirmDialog / AlertDialog → `Modal role="alertdialog"`** (needs both `aria-labelledby` and
405
405
  `aria-describedby`; the backdrop stops dismissing by default, Escape still cancels; put the actions in