@allxsmith/bestax-bulma 5.30.0 → 5.32.0

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.
@@ -7,6 +7,7 @@ import { withSubComponents } from '../helpers/withSubComponents.js';
7
7
  import { isEventInside, getActiveElementInTree } from '../helpers/shadowDom.js';
8
8
  import { omitAttrs, ANCHOR_ONLY_ATTRS } from '../helpers/anchorAttrs.js';
9
9
  import { buttonType } from '../helpers/buttonType.js';
10
+ import { useMenuKeys, enabledMenuItems } from '../helpers/useMenuKeys.js';
10
11
 
11
12
  /**
12
13
  * Checks if code is running in a browser environment.
@@ -21,6 +22,19 @@ const isBrowser$1 = (win, doc) => typeof win !== 'undefined' && typeof doc !== '
21
22
  /**
22
23
  * The `Dropdown` component provides Bulma's versatile dropdown menu for your Bulma React UI.
23
24
  *
25
+ * Down, Enter and Space on the trigger open the menu on its first enabled
26
+ * item, and Up opens it on its last. On the trigger of a menu that's already
27
+ * open, Down and Up move focus to its first and last item. In the menu, the
28
+ * arrow keys, Home and End move between the items, and Enter and Space run
29
+ * the focused one the way a click does. Typing a letter moves to the next
30
+ * item whose text starts with it, skipping disabled ones, and letters typed
31
+ * in quick succession add up to one search. Typing searches once focus is in
32
+ * the menu, so a letter typed on the trigger does nothing. Escape closes the
33
+ * menu and focuses the trigger, and Tab closes it and lets focus move on.
34
+ * Anything focusable in the menu that isn't an item, such as a field, keeps
35
+ * its own keys apart from Escape and Tab. For a panel built around fields,
36
+ * use `Popover`.
37
+ *
24
38
  * @function
25
39
  * @param {DropdownProps} props - Props for the Dropdown component.
26
40
  * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the root dropdown element.
@@ -31,6 +45,8 @@ const DropdownComponent = forwardRef(function DropdownComponent({ label, childre
31
45
  const [active, setActive] = useState(!!activeProp);
32
46
  const dropdownRef = useRef(null);
33
47
  const triggerRef = useRef(null);
48
+ const menuRef = useRef(null);
49
+ const menuKeys = useMenuKeys();
34
50
  const pendingFocusRef = useRef(null);
35
51
  // Cleanup returned by a consumer's callback ref on attach, held until detach.
36
52
  const consumerCleanupRef = useRef(null);
@@ -118,29 +134,23 @@ const DropdownComponent = forwardRef(function DropdownComponent({ label, childre
118
134
  }
119
135
  }
120
136
  };
121
- const getMenuItems = () => {
122
- /* istanbul ignore next: dropdownRef.current is never null once mounted */
123
- if (!dropdownRef.current)
124
- return [];
125
- return Array.from(
126
- // Every menu-item role, so an item a caller gives `menuitemcheckbox`
127
- // or `menuitemradio` (a filter or sort menu) stays reachable.
128
- dropdownRef.current.querySelectorAll('[role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]')).filter(el => !el.hasAttribute('disabled') &&
129
- el.getAttribute('aria-disabled') !== 'true');
137
+ const focusEdgeItem = (edge) => {
138
+ const items = enabledMenuItems(menuRef.current);
139
+ items[edge === 'first' ? 0 : items.length - 1]?.focus();
130
140
  };
131
- // Focus the pending menu item once the menu becomes visible; the item is
132
- // unfocusable while `display: none` applies, so this must wait for the
133
- // `is-active` class to actually land in the DOM.
141
+ // Once the menu shows, forget a search typed just before it last closed,
142
+ // and focus the pending item. The item is unfocusable while
143
+ // `display: none` applies, so this must wait for the `is-active` class to
144
+ // actually land in the DOM.
134
145
  useEffect(() => {
135
- if (!active || !pendingFocusRef.current)
146
+ if (!active)
136
147
  return;
137
- const items = getMenuItems();
138
- if (items.length) {
139
- const index = pendingFocusRef.current === 'first' ? 0 : items.length - 1;
140
- items[index].focus();
141
- }
148
+ menuKeys.reset();
149
+ if (!pendingFocusRef.current)
150
+ return;
151
+ focusEdgeItem(pendingFocusRef.current);
142
152
  pendingFocusRef.current = null;
143
- }, [active]);
153
+ }, [active, menuKeys]);
144
154
  const handleTriggerKeyDown = (e) => {
145
155
  if (disabled)
146
156
  return;
@@ -153,9 +163,7 @@ const DropdownComponent = forwardRef(function DropdownComponent({ label, childre
153
163
  onActiveChange?.(true);
154
164
  }
155
165
  else {
156
- const items = getMenuItems();
157
- if (items.length)
158
- items[0].focus();
166
+ focusEdgeItem('first');
159
167
  pendingFocusRef.current = null;
160
168
  }
161
169
  break;
@@ -167,9 +175,7 @@ const DropdownComponent = forwardRef(function DropdownComponent({ label, childre
167
175
  onActiveChange?.(true);
168
176
  }
169
177
  else {
170
- const items = getMenuItems();
171
- if (items.length)
172
- items[items.length - 1].focus();
178
+ focusEdgeItem('last');
173
179
  pendingFocusRef.current = null;
174
180
  }
175
181
  break;
@@ -201,8 +207,10 @@ const DropdownComponent = forwardRef(function DropdownComponent({ label, childre
201
207
  }
202
208
  };
203
209
  const handleMenuKeyDown = (e) => {
204
- // Escape and Tab close the menu regardless of whether it has any focusable
205
- // items — an empty or all-disabled menu must still honor the close contract.
210
+ // Closing is Dropdown's: Escape and Tab close the menu from anywhere in
211
+ // it, a field included, and an empty or all-disabled menu too. Moving
212
+ // between the items, running them and typeahead are the hook's, which
213
+ // acts only while focus is on the menu or one of its items.
206
214
  if (e.key === 'Escape') {
207
215
  e.preventDefault();
208
216
  setActive(false);
@@ -215,66 +223,10 @@ const DropdownComponent = forwardRef(function DropdownComponent({ label, childre
215
223
  onActiveChange?.(false);
216
224
  return;
217
225
  }
218
- const items = getMenuItems();
219
- if (!items.length)
220
- return;
221
- const currentIndex = items.indexOf(getActiveElementInTree(e.currentTarget));
222
- switch (e.key) {
223
- case 'ArrowDown': {
224
- e.preventDefault();
225
- const next = currentIndex >= 0 ? (currentIndex + 1) % items.length : 0;
226
- items[next].focus();
227
- break;
228
- }
229
- case 'ArrowUp': {
230
- e.preventDefault();
231
- const prev = currentIndex >= 0
232
- ? (currentIndex - 1 + items.length) % items.length
233
- : items.length - 1;
234
- items[prev].focus();
235
- break;
236
- }
237
- case 'Home':
238
- e.preventDefault();
239
- items[0].focus();
240
- break;
241
- case 'End':
242
- e.preventDefault();
243
- items[items.length - 1].focus();
244
- break;
245
- case 'Enter':
246
- case ' ': {
247
- // Activate the focused item by clicking it, so its `onClick` runs and
248
- // closing follows `closeOnClick` as it does for the mouse. A caller's
249
- // own key handler that prevented the default has claimed the key, and
250
- // is left to it rather than followed by a second activation.
251
- if (currentIndex < 0 || e.defaultPrevented)
252
- break;
253
- const item = items[currentIndex];
254
- // Leave the browser's own activation alone, or the item runs twice: a
255
- // `<button>` answers both keys, and a link with an `href` answers
256
- // Enter. A link does not answer Space, so Space on a link is handled
257
- // here too, which also keeps the page from scrolling.
258
- if (item.tagName === 'BUTTON')
259
- break;
260
- if (e.key === 'Enter' &&
261
- item.tagName === 'A' &&
262
- item.hasAttribute('href')) {
263
- break;
264
- }
265
- e.preventDefault();
266
- // A held key sends a keydown per auto-repeat. Clicking on each would
267
- // toggle a checkbox item over and over while `closeOnClick` is off,
268
- // so only the first press activates. The default is still prevented
269
- // on the repeats above, so a held Space does not scroll the page.
270
- if (!e.repeat)
271
- item.click();
272
- break;
273
- }
274
- }
226
+ menuKeys.onKeyDown(e);
275
227
  };
276
228
  const dropdownClasses = classNames(bulmaClasses, bulmaHelperClasses, className);
277
- return (jsxs("div", { className: dropdownClasses, ref: setRefs, id: id, "data-testid": "dropdown-root", ...rest, children: [jsx("div", { className: usePrefixedClassNames('dropdown-trigger'), children: jsxs("button", { ref: triggerRef, className: buttonClass, "aria-haspopup": "true", "aria-controls": id ? `${id}-menu` : undefined, "aria-expanded": active, onClick: handleToggle, onKeyDown: handleTriggerKeyDown, disabled: disabled, type: "button", children: [jsx("span", { children: label }), jsx("span", { className: usePrefixedClassNames('icon', 'is-small'), "aria-hidden": "true", children: jsx("i", { className: "fas fa-angle-down" }) })] }) }), jsx("div", { className: classNames(usePrefixedClassNames('dropdown-menu'), menuClassName), id: id ? `${id}-menu` : undefined, role: "menu", "data-testid": "dropdown-menu", onKeyDown: handleMenuKeyDown,
229
+ return (jsxs("div", { className: dropdownClasses, ref: setRefs, id: id, "data-testid": "dropdown-root", ...rest, children: [jsx("div", { className: usePrefixedClassNames('dropdown-trigger'), children: jsxs("button", { ref: triggerRef, className: buttonClass, "aria-haspopup": "true", "aria-controls": id ? `${id}-menu` : undefined, "aria-expanded": active, onClick: handleToggle, onKeyDown: handleTriggerKeyDown, disabled: disabled, type: "button", children: [jsx("span", { children: label }), jsx("span", { className: usePrefixedClassNames('icon', 'is-small'), "aria-hidden": "true", children: jsx("i", { className: "fas fa-angle-down" }) })] }) }), jsx("div", { className: classNames(usePrefixedClassNames('dropdown-menu'), menuClassName), id: id ? `${id}-menu` : undefined, ref: menuRef, role: "menu", "data-testid": "dropdown-menu", onKeyDown: handleMenuKeyDown,
278
230
  // The menu, not its content, takes focus from a click between items,
279
231
  // so the menu owns nothing focusable but its items.
280
232
  tabIndex: -1, children: jsx("div", { className: usePrefixedClassNames('dropdown-content'), onClick: handleMenuClick, children: children }) })] }));
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.js","sources":["../../../src/components/Dropdown.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useState,\n useRef,\n useEffect,\n} from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { getActiveElementInTree, isEventInside } from '../helpers/shadowDom';\nimport type { ConstrainedPolymorphicComponentWithoutRef } from '../helpers/polymorphic';\nimport {\n type AnchorOnlyAttributes,\n ANCHOR_ONLY_ATTRS,\n omitAttrs,\n} from '../helpers/anchorAttrs';\nimport { buttonType } from '../helpers/buttonType';\n\n/**\n * Checks if code is running in a browser environment.\n * @deprecated Dropdown's internal SSR guard, exported by accident; it will\n * be removed in the next major. Check `typeof window !== 'undefined' &&\n * typeof document !== 'undefined'` instead.\n * @param win - Window object.\n * @param doc - Document object.\n * @returns {boolean} True if in browser, false otherwise.\n */\nexport const isBrowser = (win?: typeof window, doc?: typeof document) =>\n typeof win !== 'undefined' && typeof doc !== 'undefined';\n\n/**\n * Props for the Dropdown component.\n * @extraProp {React.Ref<HTMLDivElement>} [ref] - Ref forwarded to the root dropdown element.\n */\nexport interface DropdownProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, keyof BulmaClassesProps>,\n BulmaClassesProps {\n /** The dropdown button/trigger content. */\n label: React.ReactNode;\n /** Dropdown menu items and dividers. */\n children: React.ReactNode;\n /** Additional CSS classes for root. */\n className?: string;\n /** Additional CSS classes for the dropdown menu. */\n menuClassName?: string;\n /** Whether the dropdown is open (controlled). */\n active?: boolean;\n /** Dropdown menu opens upward. */\n up?: boolean;\n /** Menu is right-aligned. */\n right?: boolean;\n /** Open on hover instead of click. */\n hoverable?: boolean;\n /** Disables the dropdown trigger. */\n disabled?: boolean;\n /** Callback when dropdown active state changes. */\n onActiveChange?: (active: boolean) => void;\n /** Close dropdown when a menu item is clicked, or activated with Enter or Space. */\n closeOnClick?: boolean;\n /** Root element ID (for aria-controls, etc). */\n id?: string;\n}\n\n/**\n * The `Dropdown` component provides Bulma's versatile dropdown menu for your Bulma React UI.\n *\n * @function\n * @param {DropdownProps} props - Props for the Dropdown component.\n * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the root dropdown element.\n * @returns {JSX.Element} The rendered dropdown.\n * @see {@link https://bulma.io/documentation/components/dropdown/ | Bulma Dropdown documentation}\n */\nconst DropdownComponent = forwardRef<HTMLDivElement, DropdownProps>(\n function DropdownComponent(\n {\n label,\n children,\n className,\n menuClassName,\n active: activeProp,\n up,\n right,\n hoverable,\n disabled,\n onActiveChange,\n closeOnClick = true,\n id,\n ...props\n },\n ref\n ) {\n const [active, setActive] = useState<boolean>(!!activeProp);\n const dropdownRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const pendingFocusRef = useRef<'first' | 'last' | null>(null);\n\n // Cleanup returned by a consumer's callback ref on attach, held until detach.\n const consumerCleanupRef = useRef<(() => void) | null>(null);\n\n const setRefs = useCallback(\n (node: HTMLDivElement | null) => {\n (dropdownRef as React.MutableRefObject<HTMLDivElement | null>).current =\n node;\n if (typeof ref === 'function') {\n // React 19 lets a callback ref return a cleanup function and detaches\n // by running it instead of calling the ref with `null`; React 18\n // discards the return value entirely. Returning it from here would be\n // a React-19-only contract, so instead we hold the cleanup and run it\n // ourselves on detach — a consumer's cleanup ref then behaves the same\n // on both majors of the CI matrix.\n if (node === null) {\n const consumerCleanup = consumerCleanupRef.current;\n consumerCleanupRef.current = null;\n if (consumerCleanup) {\n consumerCleanup();\n } else {\n ref(null);\n }\n return;\n }\n const cleanup: unknown = ref(node);\n consumerCleanupRef.current =\n typeof cleanup === 'function' ? (cleanup as () => void) : null;\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n },\n [ref]\n );\n\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n\n // Generate Bulma classes with prefix\n const bulmaClasses = usePrefixedClassNames('dropdown', {\n 'is-active': active,\n 'is-up': up,\n 'is-right': right,\n 'is-hoverable': hoverable,\n 'is-disabled': disabled,\n });\n\n const buttonClass = usePrefixedClassNames('button');\n\n // Controlled mode support: mirror the controlled `active` prop into local\n // state. This is an intentional external-prop sync (controlled/uncontrolled\n // hybrid); behavior is covered by tests and certified in-browser.\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- syncing to controlled prop\n if (typeof activeProp === 'boolean') setActive(activeProp);\n }, [activeProp]);\n\n // SSR-safe outside click\n useEffect(() => {\n if (!active) return;\n\n if (!isBrowser(window, document)) return;\n\n const handleClick = (e: MouseEvent) => {\n if (!isEventInside(e, dropdownRef.current)) {\n setActive(false);\n onActiveChange?.(false);\n }\n };\n document.addEventListener('mousedown', handleClick);\n return () => document.removeEventListener('mousedown', handleClick);\n }, [active, onActiveChange]);\n\n const handleToggle = () => {\n /* istanbul ignore next: guard is enforced by button[disabled] at the DOM level */\n if (disabled) return;\n\n const newActive = !active;\n setActive(newActive);\n onActiveChange?.(newActive);\n };\n\n const handleMenuClick = (e: React.MouseEvent<HTMLDivElement>) => {\n if (closeOnClick) {\n setActive(false);\n onActiveChange?.(false);\n // Closing hides the item that has focus, and the browser drops focus\n // to the page when that happens. Hand it back to the trigger, as\n // Escape does. An item that moved focus somewhere else keeps it there.\n // The menu around this content is what a click between items focuses.\n const menu = e.currentTarget.parentElement as HTMLElement;\n if (menu.contains(getActiveElementInTree(e.currentTarget))) {\n triggerRef.current?.focus();\n }\n }\n };\n\n const getMenuItems = (): HTMLElement[] => {\n /* istanbul ignore next: dropdownRef.current is never null once mounted */\n if (!dropdownRef.current) return [];\n return Array.from(\n // Every menu-item role, so an item a caller gives `menuitemcheckbox`\n // or `menuitemradio` (a filter or sort menu) stays reachable.\n dropdownRef.current.querySelectorAll<HTMLElement>(\n '[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]'\n )\n ).filter(\n el =>\n !el.hasAttribute('disabled') &&\n el.getAttribute('aria-disabled') !== 'true'\n );\n };\n\n // Focus the pending menu item once the menu becomes visible; the item is\n // unfocusable while `display: none` applies, so this must wait for the\n // `is-active` class to actually land in the DOM.\n useEffect(() => {\n if (!active || !pendingFocusRef.current) return;\n const items = getMenuItems();\n if (items.length) {\n const index =\n pendingFocusRef.current === 'first' ? 0 : items.length - 1;\n items[index].focus();\n }\n pendingFocusRef.current = null;\n }, [active]);\n\n const handleTriggerKeyDown = (\n e: React.KeyboardEvent<HTMLButtonElement>\n ) => {\n if (disabled) return;\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n pendingFocusRef.current = 'first';\n if (!active) {\n setActive(true);\n onActiveChange?.(true);\n } else {\n const items = getMenuItems();\n if (items.length) items[0].focus();\n pendingFocusRef.current = null;\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n pendingFocusRef.current = 'last';\n if (!active) {\n setActive(true);\n onActiveChange?.(true);\n } else {\n const items = getMenuItems();\n if (items.length) items[items.length - 1].focus();\n pendingFocusRef.current = null;\n }\n break;\n case 'Enter':\n case ' ':\n e.preventDefault();\n // A held key sends a keydown per auto-repeat. Running an item hands\n // focus back here, so without this a held Enter would reopen the\n // menu and run whichever item it focused next.\n if (e.repeat) break;\n if (!active) {\n pendingFocusRef.current = 'first';\n setActive(true);\n onActiveChange?.(true);\n } else {\n setActive(false);\n onActiveChange?.(false);\n }\n break;\n case 'Escape':\n if (active) {\n e.preventDefault();\n setActive(false);\n onActiveChange?.(false);\n }\n break;\n default:\n break;\n }\n };\n\n const handleMenuKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n // Escape and Tab close the menu regardless of whether it has any focusable\n // items — an empty or all-disabled menu must still honor the close contract.\n if (e.key === 'Escape') {\n e.preventDefault();\n setActive(false);\n onActiveChange?.(false);\n triggerRef.current?.focus();\n return;\n }\n if (e.key === 'Tab') {\n setActive(false);\n onActiveChange?.(false);\n return;\n }\n\n const items = getMenuItems();\n if (!items.length) return;\n const currentIndex = items.indexOf(\n getActiveElementInTree(e.currentTarget) as HTMLElement\n );\n switch (e.key) {\n case 'ArrowDown': {\n e.preventDefault();\n const next =\n currentIndex >= 0 ? (currentIndex + 1) % items.length : 0;\n items[next].focus();\n break;\n }\n case 'ArrowUp': {\n e.preventDefault();\n const prev =\n currentIndex >= 0\n ? (currentIndex - 1 + items.length) % items.length\n : items.length - 1;\n items[prev].focus();\n break;\n }\n case 'Home':\n e.preventDefault();\n items[0].focus();\n break;\n case 'End':\n e.preventDefault();\n items[items.length - 1].focus();\n break;\n case 'Enter':\n case ' ': {\n // Activate the focused item by clicking it, so its `onClick` runs and\n // closing follows `closeOnClick` as it does for the mouse. A caller's\n // own key handler that prevented the default has claimed the key, and\n // is left to it rather than followed by a second activation.\n if (currentIndex < 0 || e.defaultPrevented) break;\n const item = items[currentIndex];\n // Leave the browser's own activation alone, or the item runs twice: a\n // `<button>` answers both keys, and a link with an `href` answers\n // Enter. A link does not answer Space, so Space on a link is handled\n // here too, which also keeps the page from scrolling.\n if (item.tagName === 'BUTTON') break;\n if (\n e.key === 'Enter' &&\n item.tagName === 'A' &&\n item.hasAttribute('href')\n ) {\n break;\n }\n e.preventDefault();\n // A held key sends a keydown per auto-repeat. Clicking on each would\n // toggle a checkbox item over and over while `closeOnClick` is off,\n // so only the first press activates. The default is still prevented\n // on the repeats above, so a held Space does not scroll the page.\n if (!e.repeat) item.click();\n break;\n }\n default:\n break;\n }\n };\n\n const dropdownClasses = classNames(\n bulmaClasses,\n bulmaHelperClasses,\n className\n );\n\n return (\n <div\n className={dropdownClasses}\n ref={setRefs}\n id={id}\n data-testid=\"dropdown-root\"\n {...rest}\n >\n <div className={usePrefixedClassNames('dropdown-trigger')}>\n <button\n ref={triggerRef}\n className={buttonClass}\n aria-haspopup=\"true\"\n aria-controls={id ? `${id}-menu` : undefined}\n aria-expanded={active}\n onClick={handleToggle}\n onKeyDown={handleTriggerKeyDown}\n disabled={disabled}\n type=\"button\"\n >\n <span>{label}</span>\n <span\n className={usePrefixedClassNames('icon', 'is-small')}\n aria-hidden=\"true\"\n >\n <i className=\"fas fa-angle-down\" />\n </span>\n </button>\n </div>\n <div\n className={classNames(\n usePrefixedClassNames('dropdown-menu'),\n menuClassName\n )}\n id={id ? `${id}-menu` : undefined}\n role=\"menu\"\n data-testid=\"dropdown-menu\"\n onKeyDown={handleMenuKeyDown}\n // The menu, not its content, takes focus from a click between items,\n // so the menu owns nothing focusable but its items.\n tabIndex={-1}\n >\n <div\n className={usePrefixedClassNames('dropdown-content')}\n onClick={handleMenuClick}\n >\n {children}\n </div>\n </div>\n </div>\n );\n }\n);\n\n/**\n * The elements a dropdown item may render as. Bulma's dropdown markup names\n * these three and no others, so `as` is a closed set rather than an open\n * `React.ElementType`.\n */\nexport type DropdownItemElement = 'a' | 'div' | 'button';\n\n/**\n * The DropdownItem component's own props.\n */\nexport interface DropdownItemOwnProps extends BulmaClassesProps {\n /** Whether the item is active. */\n active?: boolean;\n /** Additional CSS classes. */\n className?: string;\n /** Marks the item as disabled; disabled items are skipped during keyboard navigation. Use with `as=\"button\"` for a native disabled control, or pair with `aria-disabled` on a link. */\n disabled?: boolean;\n /** Item content. */\n children?: React.ReactNode;\n}\n\n/**\n * Props for the DropdownItem component. Everything the item does not own\n * follows `as`: `href`, `target` and `rel` under the default `'a'`, `type` and\n * `form` under `'button'`, and the shared HTML attributes under any of them.\n *\n * Pinning these to `React.HTMLAttributes<HTMLElement>` instead — which is what\n * this type did before — rejected `href` on an anchor and `type` on a button,\n * both of which have always worked at runtime. Same defect as #641, in the\n * narrower shape a constrained `as` takes.\n *\n * **Name the tag you mean.** The type parameter defaults to the whole union, not\n * to the rendered element, so bare `DropdownItemProps` keeps accepting\n * `{ as: 'div' }` the way it always has. The cost is that it is not\n * distributive: `Omit` over a union keeps only the shared keys, so the bare\n * alias carries no `href` even though the component takes one under `as=\"a\"`.\n * Write `DropdownItemProps<'a'>` for the anchor's props. That is the #667 alias\n * limitation Button carries, labelled next-major because closing it is\n * source-breaking, and pinned for this component in\n * `__typetests__/polymorphic.tsx`; the component itself is unaffected.\n */\nexport type DropdownItemProps<\n T extends DropdownItemElement = DropdownItemElement,\n> = DropdownItemOwnProps &\n Omit<React.ComponentPropsWithoutRef<T>, keyof DropdownItemOwnProps | 'as'> & {\n /**\n * The element type to render.\n *\n * `'button'` renders `type=\"button\"` unless you pass `type=\"submit\"` or `type=\"reset\"`, so\n * an item inside a form does not submit it.\n */\n as?: T;\n };\n\n/**\n * The anchor's attributes, minus the one a `<button>` legitimately takes.\n *\n * `type` stays: `as=\"button\"` is a supported form and `type=\"submit\"` is valid\n * there, so stripping it would remove a working attribute. A `<div>` takes no\n * `type`, so it gets the whole `ANCHOR_ONLY_ATTRS` set instead. The set is\n * chosen by the rendered tag because that is where the reason lives (#692).\n *\n * Neither set withholds `rel`, which `Level.Item` does: React declares `rel` on\n * `HTMLAttributes` for every element, so withholding it would diverge from\n * React's own typing, the call #641 recorded for `Navbar.Link`. Level\n * withholds it anyway, because it always has.\n */\nconst STRIP_FROM_BUTTON: Readonly<\n Record<Exclude<keyof AnchorOnlyAttributes, 'type'>, true>\n> = (() => {\n const { type: _type, ...rest } = ANCHOR_ONLY_ATTRS;\n return rest;\n})();\n\n/**\n * The shape the implementation destructures. The public contract is the generic\n * `DropdownItemProps<T>` above — the body cannot see through `T`.\n */\ntype DropdownItemImplProps = DropdownItemOwnProps & {\n as?: DropdownItemElement;\n};\n\n/**\n * Bulma Dropdown item.\n *\n * @function\n * @param {DropdownItemProps} props - Props for the DropdownItem component.\n * @returns {JSX.Element} The rendered dropdown item.\n */\nexport const DropdownItem = ((itemProps: DropdownItemProps) => {\n const {\n children,\n active,\n className,\n as: Component = 'a',\n ...props\n } = itemProps as DropdownItemImplProps;\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n // The anchor's attributes reach an anchor and nothing else — `<div href>` and\n // `<button target>` are invalid HTML. The same rule Menu applies, for the same\n // reason: the type now derives these from `as`, and deriving them must not\n // quietly widen where they land. The type stops a direct caller; this stops a\n // plain-JS one, a loose `{...props}` spread, and the genericity a wrapping HOC\n // erases.\n //\n // The whole link set, not `href` alone: they all arrive together under\n // `as=\"a\"`. Menu strips `href` only, because its `as` is open and a flat set\n // would delete attributes legal on the element a caller named.\n //\n // `bestax-migrate` tracks the same question from the other side, per attribute\n // per element (`LINK_ATTR_ELEMENTS`) rather than as one set — so the two lists\n // are not interchangeable and neither derives from the other.\n //\n // Menu's condition also admits a custom component and a custom element, which\n // own their prop contracts. Here the set follows the tag: an `<a>` keeps all\n // of them, a `<button>` keeps `type`, and any other `as` keeps none of them.\n const forwarded =\n Component === 'a'\n ? rest\n : Component === 'button'\n ? omitAttrs(rest, STRIP_FROM_BUTTON)\n : omitAttrs(rest, ANCHOR_ONLY_ATTRS);\n return (\n <Component\n className={classNames(\n usePrefixedClassNames('dropdown-item', {\n 'is-active': active,\n }),\n bulmaHelperClasses,\n className\n )}\n data-testid=\"dropdown-item\"\n {...forwarded}\n // After `forwarded` for the same reason as `role` and `type` below: a\n // spread carrying `tabIndex: undefined` would otherwise erase the\n // default. The item keeps its menu role and its place in the arrow-key\n // order, but a `<div>` or an anchor without an `href` cannot take focus\n // without a tabindex, so the arrow keys stall on it.\n tabIndex={(forwarded as { tabIndex?: number }).tabIndex ?? 0}\n // After `forwarded` for the same reason as `type` below: a spread\n // carrying `role: undefined` would otherwise erase the default, and an\n // item with no role drops out of the menu and its arrow-key order.\n role={(forwarded as { role?: React.AriaRole }).role ?? 'menuitem'}\n // A menu item inside a form must not submit it. `<button>` defaults to\n // type=\"submit\", and a filter or sort menu sitting in a form is ordinary.\n // Dropdown's own trigger sets it, and `Avatar` and `Menu.Item` default it\n // the same way. A caller's `submit` or `reset` still wins, and anything\n // else becomes `button`, since HTML reads a value it does not define for\n // a button as submit too; `buttonType` says more.\n //\n // After `forwarded`, reading through it rather than before it: React\n // treats `type={undefined}` as \"remove the attribute\", and a spread\n // carrying an absent key is how that arrives. Spreading the default first\n // let such a spread erase it and restore the submit behaviour, so the\n // guard only held for callers who passed nothing.\n {...(Component === 'button'\n ? { type: buttonType((forwarded as { type?: unknown }).type) }\n : {})}\n >\n {children}\n </Component>\n );\n}) as ConstrainedPolymorphicComponentWithoutRef<\n DropdownItemOwnProps,\n DropdownItemElement,\n 'a'\n>;\n\n/**\n * Bulma Dropdown divider.\n *\n * @function\n * @returns {JSX.Element} The rendered divider element.\n */\nexport const DropdownDivider: React.FC = () => (\n <hr className={usePrefixedClassNames('dropdown-divider')} />\n);\n\n/** Bulma Dropdown component with Item and Divider sub-components. */\nexport const Dropdown = withSubComponents(\n DropdownComponent,\n {\n Item: DropdownItem,\n Divider: DropdownDivider,\n },\n 'Dropdown'\n);\n\nexport default Dropdown;\n"],"names":["isBrowser","_jsxs","_jsx"],"mappings":";;;;;;;;;;AAmBA;;;;;;;;AAQG;MACUA,WAAS,GAAG,CAAC,GAAmB,EAAE,GAAqB,KAClE,OAAO,GAAG,KAAK,WAAW,IAAI,OAAO,GAAG,KAAK;AAoC/C;;;;;;;;AAQG;AACH,MAAM,iBAAiB,GAAG,UAAU,CAClC,SAAS,iBAAiB,CACxB,EACE,KAAK,EACL,QAAQ,EACR,SAAS,EACT,aAAa,EACb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,EAAE,EAAE,SAAS,GAAG,GAAG,EACnB,GAAG,KAAK,EACT,GAAG,SAAkC;IACtC,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;AAmB3D,IAAA,MAAM,SAAS,GACb,SAAS,KAAK;AACZ,UAAE;UACA,SAAS,KAAK;AACd,cAAE,SAAS,CAAC,IAAI,EAAE,iBAAiB;AACnC,cAAE,SAAS,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAC1C,QACEA,GAAA,CAAC,SAAS,EAAA,EACR,SAAS,EAAE,UAAU,CACnB,qBAAqB,CAAC,eAAe,EAAE;AACrC,YAAA,WAAW,EAAE,MAAM;SACpB,CAAC,EACF,kBAAkB,EAClB,SAAS,CACV,EAAA,aAAA,EACW,eAAe,KACvB,SAAS;;;;;;AAMb,QAAA,QAAQ,EAAG,SAAmC,CAAC,QAAQ,IAAI,CAAC;;;;QAI5D,IAAI,EAAG,SAAuC,CAAC,IAAI,IAAI,UAAU,EAAA,IAa5D,SAAS,KAAK;cACf,EAAE,IAAI,EAAE,UAAU,CAAE,SAAgC,CAAC,IAAI,CAAC;AAC5D,cAAE,EAAE,CAAC,YAEN,QAAQ,EAAA,CACC;AAEhB,CAAC;AAMD;;;;;AAKG;AACI,MAAM,eAAe,GAAa,OACvCA,GAAA,CAAA,IAAA,EAAA,EAAI,SAAS,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,EAAA,CAAI;AAG9D;AACO,MAAM,QAAQ,GAAG,iBAAiB,CACvC,iBAAiB,EACjB;AACE,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,OAAO,EAAE,eAAe;CACzB,EACD,UAAU;;"}
1
+ {"version":3,"file":"Dropdown.js","sources":["../../../src/components/Dropdown.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useState,\n useRef,\n useEffect,\n} from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { getActiveElementInTree, isEventInside } from '../helpers/shadowDom';\nimport type { ConstrainedPolymorphicComponentWithoutRef } from '../helpers/polymorphic';\nimport {\n type AnchorOnlyAttributes,\n ANCHOR_ONLY_ATTRS,\n omitAttrs,\n} from '../helpers/anchorAttrs';\nimport { buttonType } from '../helpers/buttonType';\nimport { enabledMenuItems, useMenuKeys } from '../helpers/useMenuKeys';\n\n/**\n * Checks if code is running in a browser environment.\n * @deprecated Dropdown's internal SSR guard, exported by accident; it will\n * be removed in the next major. Check `typeof window !== 'undefined' &&\n * typeof document !== 'undefined'` instead.\n * @param win - Window object.\n * @param doc - Document object.\n * @returns {boolean} True if in browser, false otherwise.\n */\nexport const isBrowser = (win?: typeof window, doc?: typeof document) =>\n typeof win !== 'undefined' && typeof doc !== 'undefined';\n\n/**\n * Props for the Dropdown component.\n * @extraProp {React.Ref<HTMLDivElement>} [ref] - Ref forwarded to the root dropdown element.\n */\nexport interface DropdownProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, keyof BulmaClassesProps>,\n BulmaClassesProps {\n /** The dropdown button/trigger content. */\n label: React.ReactNode;\n /** Dropdown menu items and dividers. */\n children: React.ReactNode;\n /** Additional CSS classes for root. */\n className?: string;\n /** Additional CSS classes for the dropdown menu. */\n menuClassName?: string;\n /** Whether the dropdown is open (controlled). */\n active?: boolean;\n /** Dropdown menu opens upward. */\n up?: boolean;\n /** Menu is right-aligned. */\n right?: boolean;\n /** Open on hover instead of click. */\n hoverable?: boolean;\n /** Disables the dropdown trigger. */\n disabled?: boolean;\n /** Callback when dropdown active state changes. */\n onActiveChange?: (active: boolean) => void;\n /** Close dropdown when a menu item is clicked, or activated with Enter or Space. */\n closeOnClick?: boolean;\n /** Root element ID (for aria-controls, etc). */\n id?: string;\n}\n\n/**\n * The `Dropdown` component provides Bulma's versatile dropdown menu for your Bulma React UI.\n *\n * Down, Enter and Space on the trigger open the menu on its first enabled\n * item, and Up opens it on its last. On the trigger of a menu that's already\n * open, Down and Up move focus to its first and last item. In the menu, the\n * arrow keys, Home and End move between the items, and Enter and Space run\n * the focused one the way a click does. Typing a letter moves to the next\n * item whose text starts with it, skipping disabled ones, and letters typed\n * in quick succession add up to one search. Typing searches once focus is in\n * the menu, so a letter typed on the trigger does nothing. Escape closes the\n * menu and focuses the trigger, and Tab closes it and lets focus move on.\n * Anything focusable in the menu that isn't an item, such as a field, keeps\n * its own keys apart from Escape and Tab. For a panel built around fields,\n * use `Popover`.\n *\n * @function\n * @param {DropdownProps} props - Props for the Dropdown component.\n * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the root dropdown element.\n * @returns {JSX.Element} The rendered dropdown.\n * @see {@link https://bulma.io/documentation/components/dropdown/ | Bulma Dropdown documentation}\n */\nconst DropdownComponent = forwardRef<HTMLDivElement, DropdownProps>(\n function DropdownComponent(\n {\n label,\n children,\n className,\n menuClassName,\n active: activeProp,\n up,\n right,\n hoverable,\n disabled,\n onActiveChange,\n closeOnClick = true,\n id,\n ...props\n },\n ref\n ) {\n const [active, setActive] = useState<boolean>(!!activeProp);\n const dropdownRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const menuRef = useRef<HTMLDivElement>(null);\n const menuKeys = useMenuKeys();\n const pendingFocusRef = useRef<'first' | 'last' | null>(null);\n\n // Cleanup returned by a consumer's callback ref on attach, held until detach.\n const consumerCleanupRef = useRef<(() => void) | null>(null);\n\n const setRefs = useCallback(\n (node: HTMLDivElement | null) => {\n (dropdownRef as React.MutableRefObject<HTMLDivElement | null>).current =\n node;\n if (typeof ref === 'function') {\n // React 19 lets a callback ref return a cleanup function and detaches\n // by running it instead of calling the ref with `null`; React 18\n // discards the return value entirely. Returning it from here would be\n // a React-19-only contract, so instead we hold the cleanup and run it\n // ourselves on detach — a consumer's cleanup ref then behaves the same\n // on both majors of the CI matrix.\n if (node === null) {\n const consumerCleanup = consumerCleanupRef.current;\n consumerCleanupRef.current = null;\n if (consumerCleanup) {\n consumerCleanup();\n } else {\n ref(null);\n }\n return;\n }\n const cleanup: unknown = ref(node);\n consumerCleanupRef.current =\n typeof cleanup === 'function' ? (cleanup as () => void) : null;\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n },\n [ref]\n );\n\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n\n // Generate Bulma classes with prefix\n const bulmaClasses = usePrefixedClassNames('dropdown', {\n 'is-active': active,\n 'is-up': up,\n 'is-right': right,\n 'is-hoverable': hoverable,\n 'is-disabled': disabled,\n });\n\n const buttonClass = usePrefixedClassNames('button');\n\n // Controlled mode support: mirror the controlled `active` prop into local\n // state. This is an intentional external-prop sync (controlled/uncontrolled\n // hybrid); behavior is covered by tests and certified in-browser.\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- syncing to controlled prop\n if (typeof activeProp === 'boolean') setActive(activeProp);\n }, [activeProp]);\n\n // SSR-safe outside click\n useEffect(() => {\n if (!active) return;\n\n if (!isBrowser(window, document)) return;\n\n const handleClick = (e: MouseEvent) => {\n if (!isEventInside(e, dropdownRef.current)) {\n setActive(false);\n onActiveChange?.(false);\n }\n };\n document.addEventListener('mousedown', handleClick);\n return () => document.removeEventListener('mousedown', handleClick);\n }, [active, onActiveChange]);\n\n const handleToggle = () => {\n /* istanbul ignore next: guard is enforced by button[disabled] at the DOM level */\n if (disabled) return;\n\n const newActive = !active;\n setActive(newActive);\n onActiveChange?.(newActive);\n };\n\n const handleMenuClick = (e: React.MouseEvent<HTMLDivElement>) => {\n if (closeOnClick) {\n setActive(false);\n onActiveChange?.(false);\n // Closing hides the item that has focus, and the browser drops focus\n // to the page when that happens. Hand it back to the trigger, as\n // Escape does. An item that moved focus somewhere else keeps it there.\n // The menu around this content is what a click between items focuses.\n const menu = e.currentTarget.parentElement as HTMLElement;\n if (menu.contains(getActiveElementInTree(e.currentTarget))) {\n triggerRef.current?.focus();\n }\n }\n };\n\n const focusEdgeItem = (edge: 'first' | 'last') => {\n const items = enabledMenuItems(menuRef.current as HTMLElement);\n items[edge === 'first' ? 0 : items.length - 1]?.focus();\n };\n\n // Once the menu shows, forget a search typed just before it last closed,\n // and focus the pending item. The item is unfocusable while\n // `display: none` applies, so this must wait for the `is-active` class to\n // actually land in the DOM.\n useEffect(() => {\n if (!active) return;\n menuKeys.reset();\n if (!pendingFocusRef.current) return;\n focusEdgeItem(pendingFocusRef.current);\n pendingFocusRef.current = null;\n }, [active, menuKeys]);\n\n const handleTriggerKeyDown = (\n e: React.KeyboardEvent<HTMLButtonElement>\n ) => {\n if (disabled) return;\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n pendingFocusRef.current = 'first';\n if (!active) {\n setActive(true);\n onActiveChange?.(true);\n } else {\n focusEdgeItem('first');\n pendingFocusRef.current = null;\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n pendingFocusRef.current = 'last';\n if (!active) {\n setActive(true);\n onActiveChange?.(true);\n } else {\n focusEdgeItem('last');\n pendingFocusRef.current = null;\n }\n break;\n case 'Enter':\n case ' ':\n e.preventDefault();\n // A held key sends a keydown per auto-repeat. Running an item hands\n // focus back here, so without this a held Enter would reopen the\n // menu and run whichever item it focused next.\n if (e.repeat) break;\n if (!active) {\n pendingFocusRef.current = 'first';\n setActive(true);\n onActiveChange?.(true);\n } else {\n setActive(false);\n onActiveChange?.(false);\n }\n break;\n case 'Escape':\n if (active) {\n e.preventDefault();\n setActive(false);\n onActiveChange?.(false);\n }\n break;\n default:\n break;\n }\n };\n\n const handleMenuKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n // Closing is Dropdown's: Escape and Tab close the menu from anywhere in\n // it, a field included, and an empty or all-disabled menu too. Moving\n // between the items, running them and typeahead are the hook's, which\n // acts only while focus is on the menu or one of its items.\n if (e.key === 'Escape') {\n e.preventDefault();\n setActive(false);\n onActiveChange?.(false);\n triggerRef.current?.focus();\n return;\n }\n if (e.key === 'Tab') {\n setActive(false);\n onActiveChange?.(false);\n return;\n }\n\n menuKeys.onKeyDown(e);\n };\n\n const dropdownClasses = classNames(\n bulmaClasses,\n bulmaHelperClasses,\n className\n );\n\n return (\n <div\n className={dropdownClasses}\n ref={setRefs}\n id={id}\n data-testid=\"dropdown-root\"\n {...rest}\n >\n <div className={usePrefixedClassNames('dropdown-trigger')}>\n <button\n ref={triggerRef}\n className={buttonClass}\n aria-haspopup=\"true\"\n aria-controls={id ? `${id}-menu` : undefined}\n aria-expanded={active}\n onClick={handleToggle}\n onKeyDown={handleTriggerKeyDown}\n disabled={disabled}\n type=\"button\"\n >\n <span>{label}</span>\n <span\n className={usePrefixedClassNames('icon', 'is-small')}\n aria-hidden=\"true\"\n >\n <i className=\"fas fa-angle-down\" />\n </span>\n </button>\n </div>\n <div\n className={classNames(\n usePrefixedClassNames('dropdown-menu'),\n menuClassName\n )}\n id={id ? `${id}-menu` : undefined}\n ref={menuRef}\n role=\"menu\"\n data-testid=\"dropdown-menu\"\n onKeyDown={handleMenuKeyDown}\n // The menu, not its content, takes focus from a click between items,\n // so the menu owns nothing focusable but its items.\n tabIndex={-1}\n >\n <div\n className={usePrefixedClassNames('dropdown-content')}\n onClick={handleMenuClick}\n >\n {children}\n </div>\n </div>\n </div>\n );\n }\n);\n\n/**\n * The elements a dropdown item may render as. Bulma's dropdown markup names\n * these three and no others, so `as` is a closed set rather than an open\n * `React.ElementType`.\n */\nexport type DropdownItemElement = 'a' | 'div' | 'button';\n\n/**\n * The DropdownItem component's own props.\n */\nexport interface DropdownItemOwnProps extends BulmaClassesProps {\n /** Whether the item is active. */\n active?: boolean;\n /** Additional CSS classes. */\n className?: string;\n /** Marks the item as disabled; disabled items are skipped during keyboard navigation. Use with `as=\"button\"` for a native disabled control, or pair with `aria-disabled` on a link. */\n disabled?: boolean;\n /** Item content. */\n children?: React.ReactNode;\n}\n\n/**\n * Props for the DropdownItem component. Everything the item does not own\n * follows `as`: `href`, `target` and `rel` under the default `'a'`, `type` and\n * `form` under `'button'`, and the shared HTML attributes under any of them.\n *\n * Pinning these to `React.HTMLAttributes<HTMLElement>` instead — which is what\n * this type did before — rejected `href` on an anchor and `type` on a button,\n * both of which have always worked at runtime. Same defect as #641, in the\n * narrower shape a constrained `as` takes.\n *\n * **Name the tag you mean.** The type parameter defaults to the whole union, not\n * to the rendered element, so bare `DropdownItemProps` keeps accepting\n * `{ as: 'div' }` the way it always has. The cost is that it is not\n * distributive: `Omit` over a union keeps only the shared keys, so the bare\n * alias carries no `href` even though the component takes one under `as=\"a\"`.\n * Write `DropdownItemProps<'a'>` for the anchor's props. That is the #667 alias\n * limitation Button carries, labelled next-major because closing it is\n * source-breaking, and pinned for this component in\n * `__typetests__/polymorphic.tsx`; the component itself is unaffected.\n */\nexport type DropdownItemProps<\n T extends DropdownItemElement = DropdownItemElement,\n> = DropdownItemOwnProps &\n Omit<React.ComponentPropsWithoutRef<T>, keyof DropdownItemOwnProps | 'as'> & {\n /**\n * The element type to render.\n *\n * `'button'` renders `type=\"button\"` unless you pass `type=\"submit\"` or `type=\"reset\"`, so\n * an item inside a form does not submit it.\n */\n as?: T;\n };\n\n/**\n * The anchor's attributes, minus the one a `<button>` legitimately takes.\n *\n * `type` stays: `as=\"button\"` is a supported form and `type=\"submit\"` is valid\n * there, so stripping it would remove a working attribute. A `<div>` takes no\n * `type`, so it gets the whole `ANCHOR_ONLY_ATTRS` set instead. The set is\n * chosen by the rendered tag because that is where the reason lives (#692).\n *\n * Neither set withholds `rel`, which `Level.Item` does: React declares `rel` on\n * `HTMLAttributes` for every element, so withholding it would diverge from\n * React's own typing, the call #641 recorded for `Navbar.Link`. Level\n * withholds it anyway, because it always has.\n */\nconst STRIP_FROM_BUTTON: Readonly<\n Record<Exclude<keyof AnchorOnlyAttributes, 'type'>, true>\n> = (() => {\n const { type: _type, ...rest } = ANCHOR_ONLY_ATTRS;\n return rest;\n})();\n\n/**\n * The shape the implementation destructures. The public contract is the generic\n * `DropdownItemProps<T>` above — the body cannot see through `T`.\n */\ntype DropdownItemImplProps = DropdownItemOwnProps & {\n as?: DropdownItemElement;\n};\n\n/**\n * Bulma Dropdown item.\n *\n * @function\n * @param {DropdownItemProps} props - Props for the DropdownItem component.\n * @returns {JSX.Element} The rendered dropdown item.\n */\nexport const DropdownItem = ((itemProps: DropdownItemProps) => {\n const {\n children,\n active,\n className,\n as: Component = 'a',\n ...props\n } = itemProps as DropdownItemImplProps;\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n // The anchor's attributes reach an anchor and nothing else — `<div href>` and\n // `<button target>` are invalid HTML. The same rule Menu applies, for the same\n // reason: the type now derives these from `as`, and deriving them must not\n // quietly widen where they land. The type stops a direct caller; this stops a\n // plain-JS one, a loose `{...props}` spread, and the genericity a wrapping HOC\n // erases.\n //\n // The whole link set, not `href` alone: they all arrive together under\n // `as=\"a\"`. Menu strips `href` only, because its `as` is open and a flat set\n // would delete attributes legal on the element a caller named.\n //\n // `bestax-migrate` tracks the same question from the other side, per attribute\n // per element (`LINK_ATTR_ELEMENTS`) rather than as one set — so the two lists\n // are not interchangeable and neither derives from the other.\n //\n // Menu's condition also admits a custom component and a custom element, which\n // own their prop contracts. Here the set follows the tag: an `<a>` keeps all\n // of them, a `<button>` keeps `type`, and any other `as` keeps none of them.\n const forwarded =\n Component === 'a'\n ? rest\n : Component === 'button'\n ? omitAttrs(rest, STRIP_FROM_BUTTON)\n : omitAttrs(rest, ANCHOR_ONLY_ATTRS);\n return (\n <Component\n className={classNames(\n usePrefixedClassNames('dropdown-item', {\n 'is-active': active,\n }),\n bulmaHelperClasses,\n className\n )}\n data-testid=\"dropdown-item\"\n {...forwarded}\n // After `forwarded` for the same reason as `role` and `type` below: a\n // spread carrying `tabIndex: undefined` would otherwise erase the\n // default. The item keeps its menu role and its place in the arrow-key\n // order, but a `<div>` or an anchor without an `href` cannot take focus\n // without a tabindex, so the arrow keys stall on it.\n tabIndex={(forwarded as { tabIndex?: number }).tabIndex ?? 0}\n // After `forwarded` for the same reason as `type` below: a spread\n // carrying `role: undefined` would otherwise erase the default, and an\n // item with no role drops out of the menu and its arrow-key order.\n role={(forwarded as { role?: React.AriaRole }).role ?? 'menuitem'}\n // A menu item inside a form must not submit it. `<button>` defaults to\n // type=\"submit\", and a filter or sort menu sitting in a form is ordinary.\n // Dropdown's own trigger sets it, and `Avatar` and `Menu.Item` default it\n // the same way. A caller's `submit` or `reset` still wins, and anything\n // else becomes `button`, since HTML reads a value it does not define for\n // a button as submit too; `buttonType` says more.\n //\n // After `forwarded`, reading through it rather than before it: React\n // treats `type={undefined}` as \"remove the attribute\", and a spread\n // carrying an absent key is how that arrives. Spreading the default first\n // let such a spread erase it and restore the submit behaviour, so the\n // guard only held for callers who passed nothing.\n {...(Component === 'button'\n ? { type: buttonType((forwarded as { type?: unknown }).type) }\n : {})}\n >\n {children}\n </Component>\n );\n}) as ConstrainedPolymorphicComponentWithoutRef<\n DropdownItemOwnProps,\n DropdownItemElement,\n 'a'\n>;\n\n/**\n * Bulma Dropdown divider.\n *\n * @function\n * @returns {JSX.Element} The rendered divider element.\n */\nexport const DropdownDivider: React.FC = () => (\n <hr className={usePrefixedClassNames('dropdown-divider')} />\n);\n\n/** Bulma Dropdown component with Item and Divider sub-components. */\nexport const Dropdown = withSubComponents(\n DropdownComponent,\n {\n Item: DropdownItem,\n Divider: DropdownDivider,\n },\n 'Dropdown'\n);\n\nexport default Dropdown;\n"],"names":["isBrowser","_jsxs","_jsx"],"mappings":";;;;;;;;;;;AAoBA;;;;;;;;AAQG;MACUA,WAAS,GAAG,CAAC,GAAmB,EAAE,GAAqB,KAClE,OAAO,GAAG,KAAK,WAAW,IAAI,OAAO,GAAG,KAAK;AAoC/C;;;;;;;;;;;;;;;;;;;;;AAqBG;AACH,MAAM,iBAAiB,GAAG,UAAU,CAClC,SAAS,iBAAiB,CACxB,EACE,KAAK,EACL,QAAQ,EACR,SAAS,EACT,aAAa,EACb,MAAM,EAAE,UAAU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AAC;;;;QAI5D,IAAI,EAAG,SAAuC,CAAC,IAAI,IAAI,UAAU,EAAA,IAa5D,SAAS,KAAK;cACf,EAAE,IAAI,EAAE,UAAU,CAAE,SAAgC,CAAC,IAAI,CAAC;AAC5D,cAAE,EAAE,CAAC,YAEN,QAAQ,EAAA,CACC;AAEhB,CAAC;AAMD;;;;;AAKG;AACI,MAAM,eAAe,GAAa,OACvCA,GAAA,CAAA,IAAA,EAAA,EAAI,SAAS,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,EAAA,CAAI;AAG9D;AACO,MAAM,QAAQ,GAAG,iBAAiB,CACvC,iBAAiB,EACjB;AACE,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,OAAO,EAAE,eAAe;CACzB,EACD,UAAU;;"}
@@ -0,0 +1,230 @@
1
+ /* @allxsmith/bestax-bulma — AI agents: see AGENTS.md in the package root, or https://bestax.io/llms.txt */
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { createContext, forwardRef, useState, useCallback, useEffect, useContext, useRef } from 'react';
4
+ import { Button } from '../elements/Button.js';
5
+ import { usePrefixedClassNames, classNames } from '../helpers/classNames.js';
6
+ import { useBulmaClasses } from '../helpers/useBulmaClasses.js';
7
+ import { withSubComponents } from '../helpers/withSubComponents.js';
8
+ import { warnOnce } from '../helpers/devWarnings.js';
9
+ import { useClientLayoutEffect } from '../helpers/useClientLayoutEffect.js';
10
+
11
+ // Not exported, so it stays out of the public API that `index.ts` re-exports.
12
+ const SegmentedControlContext = createContext(null);
13
+ /** Sorts mounted segments into the order they sit in the page. */
14
+ const inDocumentOrder = (a, b) => a.node.compareDocumentPosition(b.node) & Node.DOCUMENT_POSITION_FOLLOWING
15
+ ? -1
16
+ : 1;
17
+ /** How far each arrow key moves along the row. */
18
+ const STEPS = {
19
+ ArrowRight: 1,
20
+ ArrowDown: 1,
21
+ ArrowLeft: -1,
22
+ ArrowUp: -1,
23
+ };
24
+ /**
25
+ * The segment a key moves to, found among the segments of the same group in
26
+ * DOM order, skipping disabled ones and wrapping at either end. `undefined`
27
+ * for a key the group leaves alone, when no enabled segment is left, or when
28
+ * the segment isn't inside its row in the page, as a portaled one isn't.
29
+ */
30
+ function segmentFor(current, key) {
31
+ const group = current.closest('[role="radiogroup"]');
32
+ if (!group)
33
+ return undefined;
34
+ const segments = Array.from(group.querySelectorAll('[role="radio"]'));
35
+ const enabled = segments.filter(segment => !segment.disabled);
36
+ if (key === 'Home')
37
+ return enabled[0];
38
+ if (key === 'End')
39
+ return enabled[enabled.length - 1];
40
+ const step = STEPS[key];
41
+ if (!step)
42
+ return undefined;
43
+ const at = segments.indexOf(current);
44
+ for (let i = 1; i <= segments.length; i += 1) {
45
+ const candidate = segments[(at + step * i + segments.length) % segments.length];
46
+ if (!candidate.disabled)
47
+ return candidate;
48
+ }
49
+ return undefined;
50
+ }
51
+ /**
52
+ * The `SegmentedControl` component renders a row of buttons where only one can be on, and tells a screen reader it's a radio group.
53
+ *
54
+ * It's Bulma's `.buttons.has-addons` row, with the checked segment filled and
55
+ * marked `is-selected`, the way Bulma's button docs show it. To a screen
56
+ * reader it's `role="radiogroup"`, with `role="radio"` and `aria-checked` on
57
+ * each segment, which is how the APG toolbar example marks its alignment
58
+ * buttons. The keys follow the APG radio group: the row is one tab stop, the
59
+ * arrow keys move to the next or previous enabled segment and check it,
60
+ * wrapping at either end, Home and End go to the first and last, and Space
61
+ * checks the focused segment. Once a segment is checked, one always is.
62
+ *
63
+ * It carries no form value. A choice that's sent with a form is `Radios`.
64
+ *
65
+ * @function
66
+ * @param {SegmentedControlProps} props - Props for the SegmentedControl component.
67
+ * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the row's `<div>`.
68
+ * @returns {JSX.Element} The rendered segmented control.
69
+ * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/radio/ | APG radio group pattern}
70
+ * @see {@link https://bulma.io/documentation/elements/button/#list-of-buttons | Bulma list of buttons}
71
+ *
72
+ * @example
73
+ * <SegmentedControl aria-label="Text alignment" defaultValue="left">
74
+ * <SegmentedControl.Segment value="left">Left</SegmentedControl.Segment>
75
+ * <SegmentedControl.Segment value="center">Center</SegmentedControl.Segment>
76
+ * <SegmentedControl.Segment value="right">Right</SegmentedControl.Segment>
77
+ * </SegmentedControl>
78
+ */
79
+ const SegmentedControlRoot = forwardRef(function SegmentedControl({ value, defaultValue, onChange, color = 'link', size, hasAddons = true, isCentered, isRight, className, children, ...props }, ref) {
80
+ const { bulmaHelperClasses, rest } = useBulmaClasses({ ...props });
81
+ // Controlled vs uncontrolled, as in Tabs and Collapses.
82
+ const isControlled = value !== undefined;
83
+ const [internalValue, setInternalValue] = useState(defaultValue);
84
+ const checked = isControlled ? (value ?? undefined) : internalValue;
85
+ const select = (next) => {
86
+ if (next === checked)
87
+ return;
88
+ if (!isControlled)
89
+ setInternalValue(next);
90
+ onChange?.(next);
91
+ };
92
+ // The segments mount and register from an effect, so the group knows
93
+ // which can hold the tab stop wherever in the tree they sit.
94
+ const [segments, setSegments] = useState([]);
95
+ const register = useCallback((record) => {
96
+ setSegments(prev => [...prev, record]);
97
+ return () => setSegments(prev => prev.filter(r => r !== record));
98
+ }, []);
99
+ const [focused, setFocused] = useState();
100
+ // The first enabled segment in the page, sorted when it's read rather
101
+ // than when a segment registers, so reordered segments are seen too. It's
102
+ // read after the commit: a render runs before React moves the nodes, so
103
+ // sorting there would find the old order.
104
+ const [firstEnabled, setFirstEnabled] = useState();
105
+ useClientLayoutEffect(() => {
106
+ const inPage = segments.filter(s => !s.disabled).sort(inDocumentOrder);
107
+ setFirstEnabled(inPage[0]?.value);
108
+ }, [segments, children]);
109
+ // One tab stop for the row (roving tabindex). While focus is in the row
110
+ // the stop follows it, so Tab leaves from wherever focus is even when a
111
+ // controlled group hasn't taken the new value. Otherwise it's the checked
112
+ // segment, or the first enabled one when none is checked or the checked
113
+ // one is disabled. Before the segments register (the server render and
114
+ // the first client render) the checked one holds it, so a row with
115
+ // nothing checked has no stop until the client has rendered.
116
+ const canHoldStop = (candidate) => segments.some(s => !s.disabled && s.value === candidate);
117
+ let tabStop;
118
+ if (canHoldStop(focused))
119
+ tabStop = focused;
120
+ else if (segments.length === 0 || canHoldStop(checked))
121
+ tabStop = checked;
122
+ else
123
+ tabStop = firstEnabled;
124
+ const named = Boolean(rest['aria-label'] || rest['aria-labelledby']);
125
+ useEffect(() => {
126
+ if (!named) {
127
+ warnOnce('SegmentedControl:unnamed', '[bestax-bulma] <SegmentedControl> has no accessible name. Pass ' +
128
+ 'aria-label or aria-labelledby, so a screen reader can say what ' +
129
+ 'the choice is.');
130
+ }
131
+ }, [named]);
132
+ const rowClasses = usePrefixedClassNames('buttons', {
133
+ 'has-addons': hasAddons,
134
+ 'is-centered': isCentered,
135
+ 'is-right': isRight,
136
+ [`are-${size}`]: size,
137
+ });
138
+ // The props are spread first, so the role a screen reader relies on wins
139
+ // over anything a JavaScript caller or a spread object passes along.
140
+ return (jsx(SegmentedControlContext.Provider, { value: { checked, tabStop, color, select, setFocused, register }, children: jsx("div", { ...rest, ref: ref, role: "radiogroup", className: classNames(rowClasses, bulmaHelperClasses, className), children: children }) }));
141
+ });
142
+ /**
143
+ * One option in the row: a `<button role="radio">` that's checked while the group's value is its `value`, filled with the group's `color` and marked `is-selected`.
144
+ *
145
+ * @function
146
+ * @param {SegmentedControlSegmentProps} props - Props for the segment.
147
+ * @param {React.Ref<HTMLButtonElement>} ref - Forwarded ref to the `<button>`.
148
+ * @returns {JSX.Element} The rendered segment.
149
+ */
150
+ const Segment = forwardRef(function Segment({ value, isDisabled, disabled, className, onClick, onKeyDown, onFocus, onBlur, ...props }, ref) {
151
+ const ctx = useContext(SegmentedControlContext);
152
+ const checked = ctx !== null && ctx.checked === value;
153
+ const off = Boolean(isDisabled || disabled);
154
+ // Prefixed like Button's own classes, which a hand-written
155
+ // `className="is-selected"` could not be under ConfigProvider classPrefix.
156
+ // Bulma lifts `is-selected` above its neighbours in `.buttons.has-addons`.
157
+ const selectedClass = usePrefixedClassNames({ 'is-selected': checked });
158
+ const nodeRef = useRef(null);
159
+ const setRefs = useCallback((node) => {
160
+ nodeRef.current = node;
161
+ if (typeof ref === 'function')
162
+ ref(node);
163
+ else if (ref)
164
+ ref.current = node;
165
+ }, [ref]);
166
+ const register = ctx?.register;
167
+ useEffect(() => {
168
+ if (!register) {
169
+ warnOnce('SegmentedControl.Segment:outside', '[bestax-bulma] <SegmentedControl.Segment> is outside a ' +
170
+ '<SegmentedControl>, so nothing can check it. Put it inside one.');
171
+ return undefined;
172
+ }
173
+ return register({
174
+ value,
175
+ disabled: off,
176
+ node: nodeRef.current,
177
+ });
178
+ }, [register, value, off]);
179
+ // The caller's onClick runs first, so a `preventDefault()` there keeps
180
+ // the segment from being checked. A disabled button gets no click.
181
+ const handleClick = (event) => {
182
+ onClick?.(event);
183
+ if (event.defaultPrevented)
184
+ return;
185
+ ctx?.select(value);
186
+ };
187
+ const handleKeyDown = (event) => {
188
+ onKeyDown?.(event);
189
+ if (!ctx ||
190
+ event.defaultPrevented ||
191
+ event.altKey ||
192
+ event.ctrlKey ||
193
+ event.metaKey) {
194
+ return;
195
+ }
196
+ const target = segmentFor(event.currentTarget, event.key);
197
+ if (!target)
198
+ return;
199
+ event.preventDefault();
200
+ // The row has taken this key, so nothing above it acts on it too: a
201
+ // Carousel moves its slide on the arrows from a document listener that
202
+ // doesn't read `defaultPrevented`. Keys the row leaves alone still bubble.
203
+ event.stopPropagation();
204
+ target.focus();
205
+ // The check follows focus, APG's rule for a radio group outside a
206
+ // toolbar. It goes through a click on the segment, as a native radio's
207
+ // does, so its onClick sees it. Inside a toolbar the arrows would move
208
+ // focus alone; that is the line a toolbar would change.
209
+ target.click();
210
+ };
211
+ const handleFocus = (event) => {
212
+ onFocus?.(event);
213
+ ctx?.setFocused(value);
214
+ };
215
+ // The segment focus moves to, if any, records itself straight after.
216
+ const handleBlur = (event) => {
217
+ onBlur?.(event);
218
+ ctx?.setFocused(undefined);
219
+ };
220
+ // The props are spread first, so what a radio depends on wins over
221
+ // anything a JavaScript caller or a spread object passes along: it stays
222
+ // a button, never submits, reports whether it's checked, and the group
223
+ // decides whether Tab reaches it.
224
+ return (jsx(Button, { ...props, ref: setRefs, as: "button", type: "button", role: "radio", "aria-checked": checked, tabIndex: ctx ? (ctx.tabStop === value ? 0 : -1) : undefined, isDisabled: off, color: checked ? ctx.color : undefined, className: classNames(selectedClass, className), onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur }));
225
+ });
226
+ Segment.displayName = 'SegmentedControl.Segment';
227
+ const SegmentedControl = withSubComponents(SegmentedControlRoot, { Segment }, 'SegmentedControl');
228
+
229
+ export { SegmentedControl };
230
+ //# sourceMappingURL=SegmentedControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SegmentedControl.js","sources":["../../../src/components/SegmentedControl.tsx"],"sourcesContent":["import React, {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { Button, type ButtonOwnProps } from '../elements/Button';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { warnOnce } from '../helpers/devWarnings';\nimport { useClientLayoutEffect } from '../helpers/useClientLayoutEffect';\n\n// Spelled out so the API page can list the values. The tests hold it to\n// ToggleButton's, since the checked segment fills the way a pressed toggle\n// does and for the same reasons.\n/**\n * The fills the checked segment takes: `Button`'s colors, minus `text` and\n * `ghost`, which don't fill, and `white`, `light`, `dark` and `black`, which in\n * one theme or the other fill about as light or dark as an unchecked segment\n * already is. The same set `ToggleButton` takes.\n */\nexport type SegmentedControlColor =\n 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\n/** A mounted segment, as the group needs to know it for the tab stop. */\ninterface SegmentRecord {\n value: string;\n disabled: boolean;\n node: HTMLButtonElement;\n}\n\ninterface SegmentedControlContextValue {\n /** The checked segment's value, or `undefined` while none is. */\n checked: string | undefined;\n /** The segment that holds `tabIndex={0}`, or `undefined` for none. */\n tabStop: string | undefined;\n /** The fill the checked segment takes. */\n color: SegmentedControlColor;\n /** Checks a segment, unless it's checked already. */\n select: (value: string) => void;\n /** Records which segment has focus, so the tab stop can follow it. */\n setFocused: (value: string | undefined) => void;\n register: (record: SegmentRecord) => () => void;\n}\n\n// Not exported, so it stays out of the public API that `index.ts` re-exports.\nconst SegmentedControlContext =\n createContext<SegmentedControlContextValue | null>(null);\n\n/** Sorts mounted segments into the order they sit in the page. */\nconst inDocumentOrder = (a: SegmentRecord, b: SegmentRecord) =>\n a.node.compareDocumentPosition(b.node) & Node.DOCUMENT_POSITION_FOLLOWING\n ? -1\n : 1;\n\n/** How far each arrow key moves along the row. */\nconst STEPS: Record<string, number> = {\n ArrowRight: 1,\n ArrowDown: 1,\n ArrowLeft: -1,\n ArrowUp: -1,\n};\n\n/**\n * The segment a key moves to, found among the segments of the same group in\n * DOM order, skipping disabled ones and wrapping at either end. `undefined`\n * for a key the group leaves alone, when no enabled segment is left, or when\n * the segment isn't inside its row in the page, as a portaled one isn't.\n */\nfunction segmentFor(\n current: HTMLButtonElement,\n key: string\n): HTMLButtonElement | undefined {\n const group = current.closest('[role=\"radiogroup\"]');\n if (!group) return undefined;\n const segments = Array.from(\n group.querySelectorAll<HTMLButtonElement>('[role=\"radio\"]')\n );\n const enabled = segments.filter(segment => !segment.disabled);\n\n if (key === 'Home') return enabled[0];\n if (key === 'End') return enabled[enabled.length - 1];\n\n const step = STEPS[key];\n if (!step) return undefined;\n const at = segments.indexOf(current);\n for (let i = 1; i <= segments.length; i += 1) {\n const candidate =\n segments[(at + step * i + segments.length) % segments.length];\n if (!candidate.disabled) return candidate;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// SegmentedControl (root)\n// ---------------------------------------------------------------------------\n\n/**\n * Props for the SegmentedControl component. The helper props, the other `<div>`\n * attributes and the `ref` all land on the row.\n *\n * @extraProp {string} [aria-label] - Names the group for a screen reader, such as \"Text alignment\". A radio group needs a name, so pass this or `aria-labelledby`, and a development build warns when it has neither.\n * @extraProp {string} [aria-labelledby] - The id of a visible heading or label that names the group, in place of `aria-label`.\n * @extraProp {React.Ref<HTMLDivElement>} [ref] - Ref forwarded to the row's `<div>`.\n */\nexport interface SegmentedControlProps\n extends\n Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'onChange' | 'defaultValue' | 'color' | 'role'\n >,\n Omit<\n BulmaClassesProps,\n 'color' | 'colorShade' | 'backgroundColor' | 'backgroundColorShade'\n > {\n /**\n * The checked segment's `value`, when you hold the state. Setting it makes\n * the group controlled: picking a segment only calls `onChange`, and nothing\n * changes until you pass the new value. `null` checks nothing, with the\n * tab stop `defaultValue` describes for that. Pick this or `defaultValue`\n * for the group's lifetime.\n */\n value?: string | null;\n /**\n * The segment checked to begin with, when the group holds its own state.\n * Leave it out and nothing is checked until someone picks one, and Tab\n * lands on the first enabled segment meanwhile. That fallback takes hold\n * once the row has rendered in the browser: server markup with nothing\n * checked has no tab stop until then, while a checked segment is the stop\n * from the server markup on.\n */\n defaultValue?: string;\n /**\n * Called with the newly checked segment's `value`, whether or not `value`\n * is set. The arrow keys, Home and End check the segment they move to, so\n * each of those calls it too: the check follows focus, as in a native radio\n * group. Pressing the checked segment again doesn't call it, since a\n * segmented control can't be cleared: one stays checked once one is.\n */\n onChange?: (value: string) => void;\n /**\n * The checked segment's fill. The others are plain buttons, so the fill is\n * the difference people see. Takes the same colors as `ToggleButton`, for\n * the same reason: `white`, `light`, `dark` and `black` fill about as light\n * or dark as a plain button already is in one theme or the other.\n */\n color?: SegmentedControlColor;\n /** Size of every segment, through Bulma's `are-<size>` on the row. */\n size?: 'small' | 'medium' | 'large';\n /**\n * Joins the segments into one row with no gap between them, Bulma's\n * `has-addons`. Set it to `false` for separate buttons.\n */\n hasAddons?: boolean;\n /** Centers the row. */\n isCentered?: boolean;\n /** Aligns the row to the right. */\n isRight?: boolean;\n /** Additional CSS classes to apply. */\n className?: string;\n /** The `SegmentedControl.Segment`s, each with a `value` of its own. */\n children?: React.ReactNode;\n}\n\n/**\n * The `SegmentedControl` component renders a row of buttons where only one can be on, and tells a screen reader it's a radio group.\n *\n * It's Bulma's `.buttons.has-addons` row, with the checked segment filled and\n * marked `is-selected`, the way Bulma's button docs show it. To a screen\n * reader it's `role=\"radiogroup\"`, with `role=\"radio\"` and `aria-checked` on\n * each segment, which is how the APG toolbar example marks its alignment\n * buttons. The keys follow the APG radio group: the row is one tab stop, the\n * arrow keys move to the next or previous enabled segment and check it,\n * wrapping at either end, Home and End go to the first and last, and Space\n * checks the focused segment. Once a segment is checked, one always is.\n *\n * It carries no form value. A choice that's sent with a form is `Radios`.\n *\n * @function\n * @param {SegmentedControlProps} props - Props for the SegmentedControl component.\n * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the row's `<div>`.\n * @returns {JSX.Element} The rendered segmented control.\n * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/radio/ | APG radio group pattern}\n * @see {@link https://bulma.io/documentation/elements/button/#list-of-buttons | Bulma list of buttons}\n *\n * @example\n * <SegmentedControl aria-label=\"Text alignment\" defaultValue=\"left\">\n * <SegmentedControl.Segment value=\"left\">Left</SegmentedControl.Segment>\n * <SegmentedControl.Segment value=\"center\">Center</SegmentedControl.Segment>\n * <SegmentedControl.Segment value=\"right\">Right</SegmentedControl.Segment>\n * </SegmentedControl>\n */\nconst SegmentedControlRoot = forwardRef<HTMLDivElement, SegmentedControlProps>(\n function SegmentedControl(\n {\n value,\n defaultValue,\n onChange,\n color = 'link',\n size,\n hasAddons = true,\n isCentered,\n isRight,\n className,\n children,\n ...props\n },\n ref\n ) {\n const { bulmaHelperClasses, rest } = useBulmaClasses({ ...props });\n\n // Controlled vs uncontrolled, as in Tabs and Collapses.\n const isControlled = value !== undefined;\n const [internalValue, setInternalValue] = useState(defaultValue);\n const checked = isControlled ? (value ?? undefined) : internalValue;\n\n const select = (next: string) => {\n if (next === checked) return;\n if (!isControlled) setInternalValue(next);\n onChange?.(next);\n };\n\n // The segments mount and register from an effect, so the group knows\n // which can hold the tab stop wherever in the tree they sit.\n const [segments, setSegments] = useState<SegmentRecord[]>([]);\n const register = useCallback((record: SegmentRecord) => {\n setSegments(prev => [...prev, record]);\n return () => setSegments(prev => prev.filter(r => r !== record));\n }, []);\n const [focused, setFocused] = useState<string | undefined>();\n\n // The first enabled segment in the page, sorted when it's read rather\n // than when a segment registers, so reordered segments are seen too. It's\n // read after the commit: a render runs before React moves the nodes, so\n // sorting there would find the old order.\n const [firstEnabled, setFirstEnabled] = useState<string | undefined>();\n useClientLayoutEffect(() => {\n const inPage = segments.filter(s => !s.disabled).sort(inDocumentOrder);\n setFirstEnabled(inPage[0]?.value);\n }, [segments, children]);\n\n // One tab stop for the row (roving tabindex). While focus is in the row\n // the stop follows it, so Tab leaves from wherever focus is even when a\n // controlled group hasn't taken the new value. Otherwise it's the checked\n // segment, or the first enabled one when none is checked or the checked\n // one is disabled. Before the segments register (the server render and\n // the first client render) the checked one holds it, so a row with\n // nothing checked has no stop until the client has rendered.\n const canHoldStop = (candidate: string | undefined) =>\n segments.some(s => !s.disabled && s.value === candidate);\n let tabStop: string | undefined;\n if (canHoldStop(focused)) tabStop = focused;\n else if (segments.length === 0 || canHoldStop(checked)) tabStop = checked;\n else tabStop = firstEnabled;\n\n const named = Boolean(rest['aria-label'] || rest['aria-labelledby']);\n useEffect(() => {\n if (!named) {\n warnOnce(\n 'SegmentedControl:unnamed',\n '[bestax-bulma] <SegmentedControl> has no accessible name. Pass ' +\n 'aria-label or aria-labelledby, so a screen reader can say what ' +\n 'the choice is.'\n );\n }\n }, [named]);\n\n const rowClasses = usePrefixedClassNames('buttons', {\n 'has-addons': hasAddons,\n 'is-centered': isCentered,\n 'is-right': isRight,\n [`are-${size}`]: size,\n });\n\n // The props are spread first, so the role a screen reader relies on wins\n // over anything a JavaScript caller or a spread object passes along.\n return (\n <SegmentedControlContext.Provider\n value={{ checked, tabStop, color, select, setFocused, register }}\n >\n <div\n {...rest}\n ref={ref}\n role=\"radiogroup\"\n className={classNames(rowClasses, bulmaHelperClasses, className)}\n >\n {children}\n </div>\n </SegmentedControlContext.Provider>\n );\n }\n);\n\n// ---------------------------------------------------------------------------\n// SegmentedControl.Segment\n// ---------------------------------------------------------------------------\n\n/**\n * Props for SegmentedControl.Segment. The helper props, the other button\n * attributes and the `ref` all land on the `<button>`.\n *\n * Some of `Button`'s props are left out on purpose. `as`, `type`, `role` and\n * `tabIndex`, since a segment is always a `<button type=\"button\" role=\"radio\">`\n * and the group decides which segment Tab reaches. `color`, which the group\n * sets for the checked segment, and the props that change the fill\n * (`isActive`, `isLight`, `isOutlined`, `isInverted`, `textColor`, `bgColor`\n * and their shades), since each would color it whether checked or not. `size`\n * and the width and shape props, which the row sets for every segment. And\n * `isStatic` and `isLoading`, a segment you couldn't pick.\n *\n * @extraProp {React.Ref<HTMLButtonElement>} [ref] - Ref forwarded to the `<button>`.\n */\nexport interface SegmentedControlSegmentProps\n extends\n Omit<\n ButtonOwnProps,\n | 'color'\n | 'size'\n | 'isActive'\n | 'isStatic'\n | 'isLoading'\n | 'isLight'\n | 'isOutlined'\n | 'isInverted'\n | 'isRounded'\n | 'isFullwidth'\n | 'isFullWidth'\n | 'textColor'\n | 'bgColor'\n | 'colorShade'\n | 'backgroundColorShade'\n >,\n Omit<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n | keyof ButtonOwnProps\n | 'type'\n | 'value'\n | 'role'\n | 'tabIndex'\n | 'aria-checked'\n | 'aria-pressed'\n > {\n /**\n * **Required.** What `onChange` reports when this segment is checked, and\n * what the group's `value` and `defaultValue` name it by. Unique within the\n * group.\n */\n value: string;\n /**\n * The label. An icon on its own needs an `aria-label`, so a screen reader\n * has something to say.\n */\n children?: React.ReactNode;\n /**\n * Disables the segment, the same as `disabled`: it can't be clicked, the\n * arrow keys, Home and End skip it, and it never holds the row's tab stop.\n * A checked one keeps its fill under Bulma's disabled look.\n */\n isDisabled?: boolean;\n /**\n * Not accepted: `aria-checked` follows the group's value. Declared because\n * JSX lets a hyphenated attribute through when the props don't name it.\n * @internal\n */\n 'aria-checked'?: never;\n /**\n * Not accepted: a segment is a radio, which says checked, not pressed.\n * @internal\n */\n 'aria-pressed'?: never;\n}\n\n/**\n * One option in the row: a `<button role=\"radio\">` that's checked while the group's value is its `value`, filled with the group's `color` and marked `is-selected`.\n *\n * @function\n * @param {SegmentedControlSegmentProps} props - Props for the segment.\n * @param {React.Ref<HTMLButtonElement>} ref - Forwarded ref to the `<button>`.\n * @returns {JSX.Element} The rendered segment.\n */\nconst Segment = forwardRef<HTMLButtonElement, SegmentedControlSegmentProps>(\n function Segment(\n {\n value,\n isDisabled,\n disabled,\n className,\n onClick,\n onKeyDown,\n onFocus,\n onBlur,\n ...props\n },\n ref\n ) {\n const ctx = useContext(SegmentedControlContext);\n const checked = ctx !== null && ctx.checked === value;\n const off = Boolean(isDisabled || disabled);\n\n // Prefixed like Button's own classes, which a hand-written\n // `className=\"is-selected\"` could not be under ConfigProvider classPrefix.\n // Bulma lifts `is-selected` above its neighbours in `.buttons.has-addons`.\n const selectedClass = usePrefixedClassNames({ 'is-selected': checked });\n\n const nodeRef = useRef<HTMLButtonElement | null>(null);\n const setRefs = useCallback(\n (node: HTMLButtonElement | null) => {\n nodeRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n },\n [ref]\n );\n\n const register = ctx?.register;\n useEffect(() => {\n if (!register) {\n warnOnce(\n 'SegmentedControl.Segment:outside',\n '[bestax-bulma] <SegmentedControl.Segment> is outside a ' +\n '<SegmentedControl>, so nothing can check it. Put it inside one.'\n );\n return undefined;\n }\n return register({\n value,\n disabled: off,\n node: nodeRef.current as HTMLButtonElement,\n });\n }, [register, value, off]);\n\n // The caller's onClick runs first, so a `preventDefault()` there keeps\n // the segment from being checked. A disabled button gets no click.\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented) return;\n ctx?.select(value);\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n onKeyDown?.(event);\n if (\n !ctx ||\n event.defaultPrevented ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey\n ) {\n return;\n }\n const target = segmentFor(event.currentTarget, event.key);\n if (!target) return;\n event.preventDefault();\n // The row has taken this key, so nothing above it acts on it too: a\n // Carousel moves its slide on the arrows from a document listener that\n // doesn't read `defaultPrevented`. Keys the row leaves alone still bubble.\n event.stopPropagation();\n target.focus();\n // The check follows focus, APG's rule for a radio group outside a\n // toolbar. It goes through a click on the segment, as a native radio's\n // does, so its onClick sees it. Inside a toolbar the arrows would move\n // focus alone; that is the line a toolbar would change.\n target.click();\n };\n\n const handleFocus = (event: React.FocusEvent<HTMLButtonElement>) => {\n onFocus?.(event);\n ctx?.setFocused(value);\n };\n\n // The segment focus moves to, if any, records itself straight after.\n const handleBlur = (event: React.FocusEvent<HTMLButtonElement>) => {\n onBlur?.(event);\n ctx?.setFocused(undefined);\n };\n\n // The props are spread first, so what a radio depends on wins over\n // anything a JavaScript caller or a spread object passes along: it stays\n // a button, never submits, reports whether it's checked, and the group\n // decides whether Tab reaches it.\n return (\n <Button\n {...props}\n ref={setRefs}\n as=\"button\"\n type=\"button\"\n role=\"radio\"\n aria-checked={checked}\n tabIndex={ctx ? (ctx.tabStop === value ? 0 : -1) : undefined}\n isDisabled={off}\n color={checked ? ctx.color : undefined}\n className={classNames(selectedClass, className)}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n />\n );\n }\n);\n\nSegment.displayName = 'SegmentedControl.Segment';\n\nexport const SegmentedControl = withSubComponents(\n SegmentedControlRoot,\n { Segment },\n 'SegmentedControl'\n);\n\nexport default SegmentedControl;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;AAqDA;AACA,MAAM,uB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