@allxsmith/bestax-bulma 5.34.0 → 5.34.1
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.
- package/dist/esm/form/Field.js +3 -3
- package/dist/esm/form/Field.js.map +1 -1
- package/dist/esm/form/FormContext.js +2 -1
- package/dist/esm/form/FormContext.js.map +1 -1
- package/dist/esm/form/Taginput.js +36 -6
- package/dist/esm/form/Taginput.js.map +1 -1
- package/dist/esm/form/useAutoLabelId.js.map +1 -1
- package/dist/index.cjs +40 -9
- package/dist/index.cjs.map +1 -1
- package/dist/types/form/Field.d.ts +5 -5
- package/dist/types/form/FormContext.d.ts +2 -1
- package/dist/types/form/Taginput.d.ts +8 -3
- package/dist/types/form/useAutoLabelId.d.ts +2 -2
- package/dist/types-cjs/form/Field.d.ts +5 -5
- package/dist/types-cjs/form/FormContext.d.ts +2 -1
- package/dist/types-cjs/form/Taginput.d.ts +8 -3
- package/dist/types-cjs/form/useAutoLabelId.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoLabelId.js","sources":["../../../src/form/useAutoLabelId.ts"],"sourcesContent":["import React, { useId } from 'react';\nimport type { FieldProps } from './Field';\nimport {\n useFieldLabelElementId,\n useFieldLabelFor,\n useFieldLabelId,\n useReportFieldLabelFor,\n} from './FormContext';\n\ninterface UseAutoLabelIdOptions {\n /** The convenience `label` prop as passed by the caller. */\n label: React.ReactNode;\n /** User-supplied id for the control, if any. */\n id?: string;\n /** User-supplied labelProps, if any. */\n labelProps?: FieldProps['labelProps'];\n /**\n * True when this render actually outputs the label wired to a control —\n * false inside an outer Field (label is dropped), in variants that render\n * no Field, and in modes with no labellable control (e.g. inline pickers).\n */\n rendersLabel: boolean;\n /**\n * False when this render has no input to label at all (an inline picker),\n * so it takes no id from a surrounding Field either. Defaults to true.\n */\n hasInput?: boolean;\n /**\n * True when the control also points `aria-labelledby` at the label, as a\n * range Slider's thumbs (#981) and Autocomplete's suggestion list (#998)\n * do, so it needs the label's own id. Its own label then gets one\n * (`labelProps.id` when given, otherwise a generated one), and the hook\n * returns it, or a surrounding Field's, as `labelId`.\n */\n needsLabelId?: boolean;\n}\n\n/**\n * Associates the convenience `label` prop with its control (#368): generates\n * an id for the control and returns labelProps carrying a matching `htmlFor`.\n * A user-supplied `id` is used as the target instead of the generated one, and\n * an explicit `htmlFor` key in labelProps — even set to `undefined` — disables\n * generation entirely: the user has taken over the association (#495 presence\n * semantics). When the control renders no label of its own, it adopts the id\n * a labeled Field around it offers, the way the bases do, so that Field's\n * label names it (#939); a user `id` still wins there. It tells that Field\n * when the control took its id, since the Field's label drops a `for`\n * nothing took (#1004). With `needsLabelId` it also returns the id of\n * whichever label names the control (#981).\n * Internal; not part of the public API.\n */\nexport function useAutoLabelId({\n label,\n id,\n labelProps,\n rendersLabel,\n hasInput = true,\n needsLabelId = false,\n}: UseAutoLabelIdOptions): {\n controlId: string | undefined;\n fieldLabelProps: FieldProps['labelProps'] | undefined;\n /** Whether a rendered label, its own or a surrounding Field's, points at `controlId`. */\n labelled: boolean;\n /**\n * With `needsLabelId`, the id of the label that names `controlId`, its own\n * or a surrounding Field's. Undefined when no label names it, or when a\n * Field's label wired by hand names it without an `id` in its labelProps,\n * since the Field generates none for a label wired by hand.\n */\n labelId: string | undefined;\n} {\n // Called unconditionally per the rules of hooks; SSR-safe on React 18 and 19.\n const generatedId = useId();\n // Read outside the control's own Field, so it is set only when an outer\n // Field holds the control, which then renders no label of its own.\n const fieldLabelId = useFieldLabelId();\n // What an outer Field's label points at, even when wired by hand, and the\n // id that label renders with, read together so the id is that label's.\n // Set in `grouped`/`hasAddons` Fields too when the label is wired by hand,\n // since its `for` names this one control whatever the layout (see Field).\n const fieldLabelFor = useFieldLabelFor();\n // Truthiness mirrors Field's own `if (label)` render gate.\n const active = !!label && rendersLabel;\n // Presence, not truthiness: `htmlFor: undefined` is an explicit opt-out and\n // must not leave an orphan generated id on the control.\n const userWired = !!labelProps && 'htmlFor' in labelProps;\n const adopted = !active && hasInput ? fieldLabelId : undefined;\n const controlId = id ?? (active && !userWired ? generatedId : adopted);\n // Tells a labeled Field around the control when its label's `for` names\n // the control, since it drops a `for` nothing took (#1004).\n useReportFieldLabelFor(\n fieldLabelId !== undefined && controlId === fieldLabelId\n );\n const ownLabelProps = { htmlFor: controlId, ...labelProps };\n const labelTarget = active ? ownLabelProps.htmlFor : fieldLabelFor.htmlFor;\n const labelled = !!controlId && labelTarget === controlId;\n // Only a label that names the control gets an id to point at, with the\n // suffix Field gives its own, from an id that is already unique.\n const ownLabelId =\n needsLabelId && active && labelled\n ? (labelProps?.id ?? `${generatedId}-label`)\n : undefined;\n // Inactive with a label still means an own Field may render it (pickers'\n // inline mode, Taginput at maxTags) — the explicit `htmlFor: undefined`\n // tells Field the association is owned here, so it must not generate one\n // that would dangle (#495 presence semantics).\n const fieldLabelProps = active\n ? ownLabelId\n ? { ...ownLabelProps, id: ownLabelId }\n : ownLabelProps\n : label\n ? { htmlFor: undefined, ...labelProps }\n : labelProps;\n const labelId =\n needsLabelId && labelled\n ? active\n ? ownLabelId\n : fieldLabelFor.id\n : undefined;\n return { controlId, fieldLabelProps, labelled, labelId };\n}\n\ninterface UseAutoLabelledByOptions {\n /** The convenience `label` prop as passed by the caller. */\n label: React.ReactNode;\n /** User-supplied labelProps, if any. */\n labelProps?: FieldProps['labelProps'];\n /** True when this render actually outputs the label naming the group. */\n rendersLabel: boolean;\n /**\n * The caller's remaining props. A non-empty `aria-label` among them names\n * the group, and so does any `aria-labelledby` key, even an undefined one,\n * since the group spreads them after its own attribute. Either keeps every\n * label off the group, its own and a surrounding Field's alike.\n */\n callerProps: object;\n}\n\n/**\n * Group-input counterpart of {@link useAutoLabelId} (#494): a group of\n * controls cannot take a single `htmlFor`, so instead the rendered `<label>`\n * gets a generated id and the group container points at it with\n * `aria-labelledby`. A user-supplied `labelProps.id` is used as the target\n * instead of generating one. Any caller `htmlFor` is stripped — a group label\n * names the group, never a single control — so the merged labelProps always\n * carry an explicit `htmlFor: undefined`. When the group renders no label of\n * its own, it points at the label of a labeled Field around it instead\n * (#939). A caller who named the group with `aria-label` or\n * `aria-labelledby` gets no `aria-labelledby` from either label, so their\n * name wins wherever the label sits.\n * Internal; not part of the public API.\n */\nexport function useAutoLabelledBy({\n label,\n labelProps,\n rendersLabel,\n callerProps,\n}: UseAutoLabelledByOptions): {\n ariaLabelledBy: string | undefined;\n fieldLabelProps: FieldProps['labelProps'] | undefined;\n} {\n // Called unconditionally per the rules of hooks; SSR-safe on React 18 and 19.\n const generatedId = useId();\n // Set only when an outer Field holds the group (see useAutoLabelId).\n const fieldLabelElementId = useFieldLabelElementId();\n const active = !!label && rendersLabel;\n const labelId = labelProps?.id ?? (active ? generatedId : undefined);\n const fieldLabelProps = active\n ? { ...labelProps, id: labelId, htmlFor: undefined }\n : labelProps;\n const aria = callerProps as React.AriaAttributes;\n // Presence for aria-labelledby: the caller's key replaces the attribute\n // through the spread whatever its value, and pointing it at a label would\n // only take a Rate's fallback name away. Checked before either label, so\n // the caller's name wins over the group's own `label` as it does over a\n // Field's, the way an aria-label beats a `<label for>` on a single input.\n const callerNamed = !!aria['aria-label'] || 'aria-labelledby' in aria;\n const ariaLabelledBy = callerNamed\n ? undefined\n : active\n ? labelId\n : fieldLabelElementId;\n return { ariaLabelledBy, fieldLabelProps };\n}\n"],"names":[],"mappings":";;;;AAqCA;;;;;;;;;;;;;AAaG;SACa,cAAc,CAAC,EAC7B,KAAK,EACL,EAAE,EACF,UAAU,EACV,YAAY,EACZ,QAAQ,GAAG,IAAI,EACf,YAAY,GAAG,KAAK,GACE,EAAA;;AActB,IAAA,MAAM,WAAW,GAAG,KAAK,EAAE;;;AAG3B,IAAA,MAAM,YAAY,GAAG,eAAe,EAAE;;;;;AAKtC,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;;AAExC,IAAA,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,YAAY;;;I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,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,YAAY;AACtC,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE,EAAE,KAAK,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IACpE,MAAM,eAAe,GAAG;AACtB,UAAE,EAAE,GAAG,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS;UAChD,UAAU;IACd,MAAM,IAAI,GAAG,WAAmC;;;;;;AAMhD,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,iBAAiB,IAAI,IAAI;IACrE,MAAM,cAAc,GAAG;AACrB,UAAE;AACF,UAAE;AACA,cAAE;cACA,mBAAmB;AACzB,IAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE;AAC5C;;"}
|
|
1
|
+
{"version":3,"file":"useAutoLabelId.js","sources":["../../../src/form/useAutoLabelId.ts"],"sourcesContent":["import React, { useId } from 'react';\nimport type { FieldProps } from './Field';\nimport {\n useFieldLabelElementId,\n useFieldLabelFor,\n useFieldLabelId,\n useReportFieldLabelFor,\n} from './FormContext';\n\ninterface UseAutoLabelIdOptions {\n /** The convenience `label` prop as passed by the caller. */\n label: React.ReactNode;\n /** User-supplied id for the control, if any. */\n id?: string;\n /** User-supplied labelProps, if any. */\n labelProps?: FieldProps['labelProps'];\n /**\n * True when this render actually outputs the label wired to a control —\n * false inside an outer Field (label is dropped), in variants that render\n * no Field, and in modes with no labellable control (e.g. inline pickers).\n */\n rendersLabel: boolean;\n /**\n * False when this render has no input to label at all (an inline picker),\n * so it takes no id from a surrounding Field either. Defaults to true.\n */\n hasInput?: boolean;\n /**\n * True when the control also points `aria-labelledby` at the label, as a\n * range Slider's thumbs (#981) and Autocomplete's and Taginput's\n * suggestion lists (#998, #1082) do, so it needs the label's own id. Its own label then gets one\n * (`labelProps.id` when given, otherwise a generated one), and the hook\n * returns it, or a surrounding Field's, as `labelId`.\n */\n needsLabelId?: boolean;\n}\n\n/**\n * Associates the convenience `label` prop with its control (#368): generates\n * an id for the control and returns labelProps carrying a matching `htmlFor`.\n * A user-supplied `id` is used as the target instead of the generated one, and\n * an explicit `htmlFor` key in labelProps — even set to `undefined` — disables\n * generation entirely: the user has taken over the association (#495 presence\n * semantics). When the control renders no label of its own, it adopts the id\n * a labeled Field around it offers, the way the bases do, so that Field's\n * label names it (#939); a user `id` still wins there. It tells that Field\n * when the control took its id, since the Field's label drops a `for`\n * nothing took (#1004). With `needsLabelId` it also returns the id of\n * whichever label names the control (#981).\n * Internal; not part of the public API.\n */\nexport function useAutoLabelId({\n label,\n id,\n labelProps,\n rendersLabel,\n hasInput = true,\n needsLabelId = false,\n}: UseAutoLabelIdOptions): {\n controlId: string | undefined;\n fieldLabelProps: FieldProps['labelProps'] | undefined;\n /** Whether a rendered label, its own or a surrounding Field's, points at `controlId`. */\n labelled: boolean;\n /**\n * With `needsLabelId`, the id of the label that names `controlId`, its own\n * or a surrounding Field's. Undefined when no label names it, or when a\n * Field's label wired by hand names it without an `id` in its labelProps,\n * since the Field generates none for a label wired by hand.\n */\n labelId: string | undefined;\n} {\n // Called unconditionally per the rules of hooks; SSR-safe on React 18 and 19.\n const generatedId = useId();\n // Read outside the control's own Field, so it is set only when an outer\n // Field holds the control, which then renders no label of its own.\n const fieldLabelId = useFieldLabelId();\n // What an outer Field's label points at, even when wired by hand, and the\n // id that label renders with, read together so the id is that label's.\n // Set in `grouped`/`hasAddons` Fields too when the label is wired by hand,\n // since its `for` names this one control whatever the layout (see Field).\n const fieldLabelFor = useFieldLabelFor();\n // Truthiness mirrors Field's own `if (label)` render gate.\n const active = !!label && rendersLabel;\n // Presence, not truthiness: `htmlFor: undefined` is an explicit opt-out and\n // must not leave an orphan generated id on the control.\n const userWired = !!labelProps && 'htmlFor' in labelProps;\n const adopted = !active && hasInput ? fieldLabelId : undefined;\n const controlId = id ?? (active && !userWired ? generatedId : adopted);\n // Tells a labeled Field around the control when its label's `for` names\n // the control, since it drops a `for` nothing took (#1004).\n useReportFieldLabelFor(\n fieldLabelId !== undefined && controlId === fieldLabelId\n );\n const ownLabelProps = { htmlFor: controlId, ...labelProps };\n const labelTarget = active ? ownLabelProps.htmlFor : fieldLabelFor.htmlFor;\n const labelled = !!controlId && labelTarget === controlId;\n // Only a label that names the control gets an id to point at, with the\n // suffix Field gives its own, from an id that is already unique.\n const ownLabelId =\n needsLabelId && active && labelled\n ? (labelProps?.id ?? `${generatedId}-label`)\n : undefined;\n // Inactive with a label still means an own Field may render it (pickers'\n // inline mode, Taginput at maxTags) — the explicit `htmlFor: undefined`\n // tells Field the association is owned here, so it must not generate one\n // that would dangle (#495 presence semantics).\n const fieldLabelProps = active\n ? ownLabelId\n ? { ...ownLabelProps, id: ownLabelId }\n : ownLabelProps\n : label\n ? { htmlFor: undefined, ...labelProps }\n : labelProps;\n const labelId =\n needsLabelId && labelled\n ? active\n ? ownLabelId\n : fieldLabelFor.id\n : undefined;\n return { controlId, fieldLabelProps, labelled, labelId };\n}\n\ninterface UseAutoLabelledByOptions {\n /** The convenience `label` prop as passed by the caller. */\n label: React.ReactNode;\n /** User-supplied labelProps, if any. */\n labelProps?: FieldProps['labelProps'];\n /** True when this render actually outputs the label naming the group. */\n rendersLabel: boolean;\n /**\n * The caller's remaining props. A non-empty `aria-label` among them names\n * the group, and so does any `aria-labelledby` key, even an undefined one,\n * since the group spreads them after its own attribute. Either keeps every\n * label off the group, its own and a surrounding Field's alike.\n */\n callerProps: object;\n}\n\n/**\n * Group-input counterpart of {@link useAutoLabelId} (#494): a group of\n * controls cannot take a single `htmlFor`, so instead the rendered `<label>`\n * gets a generated id and the group container points at it with\n * `aria-labelledby`. A user-supplied `labelProps.id` is used as the target\n * instead of generating one. Any caller `htmlFor` is stripped — a group label\n * names the group, never a single control — so the merged labelProps always\n * carry an explicit `htmlFor: undefined`. When the group renders no label of\n * its own, it points at the label of a labeled Field around it instead\n * (#939). A caller who named the group with `aria-label` or\n * `aria-labelledby` gets no `aria-labelledby` from either label, so their\n * name wins wherever the label sits.\n * Internal; not part of the public API.\n */\nexport function useAutoLabelledBy({\n label,\n labelProps,\n rendersLabel,\n callerProps,\n}: UseAutoLabelledByOptions): {\n ariaLabelledBy: string | undefined;\n fieldLabelProps: FieldProps['labelProps'] | undefined;\n} {\n // Called unconditionally per the rules of hooks; SSR-safe on React 18 and 19.\n const generatedId = useId();\n // Set only when an outer Field holds the group (see useAutoLabelId).\n const fieldLabelElementId = useFieldLabelElementId();\n const active = !!label && rendersLabel;\n const labelId = labelProps?.id ?? (active ? generatedId : undefined);\n const fieldLabelProps = active\n ? { ...labelProps, id: labelId, htmlFor: undefined }\n : labelProps;\n const aria = callerProps as React.AriaAttributes;\n // Presence for aria-labelledby: the caller's key replaces the attribute\n // through the spread whatever its value, and pointing it at a label would\n // only take a Rate's fallback name away. Checked before either label, so\n // the caller's name wins over the group's own `label` as it does over a\n // Field's, the way an aria-label beats a `<label for>` on a single input.\n const callerNamed = !!aria['aria-label'] || 'aria-labelledby' in aria;\n const ariaLabelledBy = callerNamed\n ? undefined\n : active\n ? labelId\n : fieldLabelElementId;\n return { ariaLabelledBy, fieldLabelProps };\n}\n"],"names":[],"mappings":";;;;AAqCA;;;;;;;;;;;;;AAaG;SACa,cAAc,CAAC,EAC7B,KAAK,EACL,EAAE,EACF,UAAU,EACV,YAAY,EACZ,QAAQ,GAAG,IAAI,EACf,YAAY,GAAG,KAAK,GACE,EAAA;;AActB,IAAA,MAAM,WAAW,GAAG,KAAK,EAAE;;;AAG3B,IAAA,MAAM,YAAY,GAAG,eAAe,EAAE;;;;;AAKtC,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;;AAExC,IAAA,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,YAAY;;;IAGtC,MAAM,SAAS,GAAG,CAAC,CAAC,UAAU,IAAI,SAAS,IAAI,UAAU;AACzD,IAAA,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,QAAQ,GAAG,YAAY,GAAG,S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AAM,eAAe,GAAG;AACtB,UAAE,EAAE,GAAG,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS;UAChD,UAAU;IACd,MAAM,IAAI,GAAG,WAAmC;;;;;;AAMhD,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,iBAAiB,IAAI,IAAI;IACrE,MAAM,cAAc,GAAG;AACrB,UAAE;AACF,UAAE;AACA,cAAE;cACA,mBAAmB;AACzB,IAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE;AAC5C;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -10694,7 +10694,8 @@ const FieldLabelForContext = React.createContext({});
|
|
|
10694
10694
|
* renders with, if it has one. An unlabeled Field passes both through
|
|
10695
10695
|
* together, so a control in the inner Field of a horizontal layout can tell
|
|
10696
10696
|
* the outer label names it, and point at that label by its id, as a range
|
|
10697
|
-
* Slider's thumbs (#981) and Autocomplete's
|
|
10697
|
+
* Slider's thumbs (#981) and Autocomplete's and Taginput's suggestion lists
|
|
10698
|
+
* (#998, #1082) do. The
|
|
10698
10699
|
* `htmlFor` is only ever compared with a control's own id, never adopted, so
|
|
10699
10700
|
* it hands out no id for a control. It keeps the generated id after the
|
|
10700
10701
|
* label drops a `for` nothing took (#1004), which no control's id matches
|
|
@@ -10949,9 +10950,9 @@ Control.displayName = 'Control';
|
|
|
10949
10950
|
* `id`, or give the horizontal `Field` a `label` prop, which renders this
|
|
10950
10951
|
* column and its `<label>` for you. A `<label>` you put here names the
|
|
10951
10952
|
* control through its `htmlFor` alone: a range `Slider`'s thumbs and an
|
|
10952
|
-
* `Autocomplete`'s suggestion list point `aria-labelledby` at
|
|
10953
|
-
* label only when its `label` prop renders it and it names the
|
|
10954
|
-
* Where it would not name the control on its own, as in an inner `Field`,
|
|
10953
|
+
* `Autocomplete`'s or `Taginput`'s suggestion list point `aria-labelledby` at
|
|
10954
|
+
* a `Field`'s label only when its `label` prop renders it and it names the
|
|
10955
|
+
* control. Where it would not name the control on its own, as in an inner `Field`,
|
|
10955
10956
|
* pass `labelProps={{ htmlFor, id }}` with a matching `id` on the control.
|
|
10956
10957
|
*
|
|
10957
10958
|
* @function
|
|
@@ -12960,7 +12961,7 @@ Autocomplete.displayName = 'Autocomplete';
|
|
|
12960
12961
|
*/
|
|
12961
12962
|
const Taginput = React.forwardRef(({
|
|
12962
12963
|
// Field props
|
|
12963
|
-
label, labelSize, labelProps, horizontal, message, messageColor, fieldClassName, value: controlledValue, defaultValue = [], data
|
|
12964
|
+
label, labelSize, labelProps, horizontal, message, messageColor, fieldClassName, value: controlledValue, defaultValue = [], data: dataProp, placeholder, field = 'label', allowNew = true, allowDuplicates = false, openOnFocus = false, removeOnKeys = true, confirmKeys = ['Enter', ','], closable = true, attached = false, maxTags, maxlength, disabled = false, readonly = false, rounded = false, ellipsis = false, hasCounter = true, onPasteSeparators = [','], beforeAdding, createTag, keepFirst = false, keepOpen = true, loading = false, ariaCloseLabel, icon, iconLibrary: iconLibraryProp, iconVariant, iconFeatures, color, tagColor, size, onChange, onAdd, onRemove, onTyping, tagTemplate, name, form, id, className, ...props }, ref) => {
|
|
12964
12965
|
const insideField = useInsideField();
|
|
12965
12966
|
const insideControl = useInsideControl();
|
|
12966
12967
|
const ownField = rendersOwnField('Taginput', {
|
|
@@ -12983,17 +12984,26 @@ label, labelSize, labelProps, horizontal, message, messageColor, fieldClassName,
|
|
|
12983
12984
|
const [inputValue, setInputValue] = React.useState('');
|
|
12984
12985
|
const [isActive, setIsActive] = React.useState(false);
|
|
12985
12986
|
const [highlightedIndex, setHighlightedIndex] = React.useState(-1);
|
|
12987
|
+
const listboxId = `${React.useId()}-listbox`;
|
|
12988
|
+
// With `data` the input offers suggestions, so it's a combobox, even
|
|
12989
|
+
// while none match. Without it there's never a list, so it stays a plain
|
|
12990
|
+
// text field.
|
|
12991
|
+
const hasSuggestions = dataProp !== undefined;
|
|
12992
|
+
const data = dataProp ?? [];
|
|
12986
12993
|
// Use controlled or internal tags
|
|
12987
12994
|
const tags = controlledValue !== undefined ? controlledValue : internalTags;
|
|
12988
12995
|
const isMaxReached = maxTags !== undefined && tags.length >= maxTags;
|
|
12989
12996
|
// At the tag limit the text input is not rendered, so there is nothing to
|
|
12990
|
-
// wire a label to, its own or a surrounding Field's.
|
|
12991
|
-
|
|
12997
|
+
// wire a label to, its own or a surrounding Field's. The suggestion list
|
|
12998
|
+
// points `aria-labelledby` at the label that names the input, so with
|
|
12999
|
+
// suggestions it needs that label's id.
|
|
13000
|
+
const { controlId, fieldLabelProps, labelled, labelId: listLabelId, } = useAutoLabelId({
|
|
12992
13001
|
label,
|
|
12993
13002
|
id,
|
|
12994
13003
|
labelProps,
|
|
12995
13004
|
rendersLabel: ownField && !isMaxReached,
|
|
12996
13005
|
hasInput: !isMaxReached,
|
|
13006
|
+
needsLabelId: hasSuggestions,
|
|
12997
13007
|
});
|
|
12998
13008
|
// Get display value from tag
|
|
12999
13009
|
const getDisplayValue = (tag) => {
|
|
@@ -13013,6 +13023,7 @@ label, labelSize, labelProps, horizontal, message, messageColor, fieldClassName,
|
|
|
13013
13023
|
const hasInput = inputValue || (openOnFocus && isActive);
|
|
13014
13024
|
return matchesInput && notAlreadyAdded && hasInput;
|
|
13015
13025
|
});
|
|
13026
|
+
const listOpen = isActive && filteredData.length > 0;
|
|
13016
13027
|
// keepFirst: auto-highlight first item when dropdown opens
|
|
13017
13028
|
React.useEffect(() => {
|
|
13018
13029
|
if (keepFirst && isActive && filteredData.length > 0) {
|
|
@@ -13253,15 +13264,35 @@ label, labelSize, labelProps, horizontal, message, messageColor, fieldClassName,
|
|
|
13253
13264
|
[`is-${messageColor}`]: !!messageColor,
|
|
13254
13265
|
});
|
|
13255
13266
|
const messageEl = message ? jsxRuntime.jsx("p", { className: helpClass, children: message }) : null;
|
|
13267
|
+
// The combobox controls its listbox and points at the highlighted option,
|
|
13268
|
+
// the way Autocomplete's does. The listbox takes its name from the label
|
|
13269
|
+
// that names the combobox, the one this renders or a surrounding Field's,
|
|
13270
|
+
// and keeps a fallback name when no label names it or the one that does
|
|
13271
|
+
// has no id to point at. While no suggestion matches there's no listbox,
|
|
13272
|
+
// so the combobox is collapsed and points at nothing. It skips a
|
|
13273
|
+
// highlighted suggestion that's blank once trimmed, since that one can't
|
|
13274
|
+
// become a tag, and the option it points at is the one marked selected.
|
|
13275
|
+
const optionId = (index) => `${listboxId}-${index}`;
|
|
13276
|
+
const activeOptionId = listOpen && filteredData[highlightedIndex]?.trim()
|
|
13277
|
+
? optionId(highlightedIndex)
|
|
13278
|
+
: undefined;
|
|
13279
|
+
const comboboxProps = {
|
|
13280
|
+
role: 'combobox',
|
|
13281
|
+
'aria-expanded': listOpen,
|
|
13282
|
+
'aria-controls': listOpen ? listboxId : undefined,
|
|
13283
|
+
'aria-activedescendant': activeOptionId,
|
|
13284
|
+
'aria-haspopup': 'listbox',
|
|
13285
|
+
'aria-autocomplete': 'list',
|
|
13286
|
+
};
|
|
13256
13287
|
const taginputElement = (jsxRuntime.jsxs("div", { ref: containerRef, className: combinedClasses, onClick: handleContainerClick, ...rest, children: [jsxRuntime.jsxs("div", { className: containerClasses, children: [icon && (jsxRuntime.jsx(Icon, { name: icon, library: resolvedLibrary, variant: iconVariant, features: iconFeatures, containerClassName: pcn('icon', 'is-left') })), jsxRuntime.jsxs("div", { className: tagsClasses, children: [tags.map((tag, index) => {
|
|
13257
13288
|
const displayVal = getDisplayValue(tag);
|
|
13258
13289
|
return (jsxRuntime.jsxs("span", { className: tagClasses, children: [tagTemplate ? (tagTemplate(tag)) : ellipsis ? (jsxRuntime.jsx("span", { title: displayVal, children: displayVal })) : (displayVal), closable && !disabled && !readonly && (jsxRuntime.jsx("button", { type: "button", className: pcn('delete', 'is-small'), onClick: e => {
|
|
13259
13290
|
e.stopPropagation();
|
|
13260
13291
|
removeTag(index);
|
|
13261
13292
|
}, "aria-label": ariaCloseLabel || `Remove ${displayVal}` }))] }, index));
|
|
13262
|
-
}), !isMaxReached && (jsxRuntime.jsx("input", { ref: combinedRef, type: "text", className: inputClasses, id: controlId, value: inputValue, placeholder: tags.length === 0 ? placeholder : undefined, disabled: disabled, readOnly: readonly, maxLength: maxlength, onChange: handleInputChange, onFocus: handleFocus, onKeyDown: handleKeyDown, onPaste: handlePaste, "aria-label": labelled ? undefined : 'Add tag' }))] }), loading && (jsxRuntime.jsx("span", { className: iconRightClass, children: jsxRuntime.jsx("span", { className: loaderClass }) }))] }),
|
|
13293
|
+
}), !isMaxReached && (jsxRuntime.jsx("input", { ref: combinedRef, type: "text", className: inputClasses, id: controlId, value: inputValue, placeholder: tags.length === 0 ? placeholder : undefined, disabled: disabled, readOnly: readonly, maxLength: maxlength, onChange: handleInputChange, onFocus: handleFocus, onKeyDown: handleKeyDown, onPaste: handlePaste, ...(hasSuggestions && comboboxProps), "aria-label": labelled ? undefined : 'Add tag' }))] }), loading && (jsxRuntime.jsx("span", { className: iconRightClass, children: jsxRuntime.jsx("span", { className: loaderClass }) }))] }), listOpen && (jsxRuntime.jsx("div", { className: dropdownMenuClasses, children: jsxRuntime.jsx("div", { ref: dropdownRef, id: listboxId, className: dropdownContentClasses, role: "listbox", "aria-labelledby": listLabelId, "aria-label": listLabelId ? undefined : 'Suggestions', children: filteredData.map((item, index) => (jsxRuntime.jsx("a", { id: optionId(index), className: pcn('dropdown-item', {
|
|
13263
13294
|
'is-active': index === highlightedIndex,
|
|
13264
|
-
}), onClick: () => addTag(item), onMouseEnter: () => setHighlightedIndex(index), role: "option", "aria-selected": index ===
|
|
13295
|
+
}), onClick: () => addTag(item), onMouseEnter: () => setHighlightedIndex(index), role: "option", "aria-selected": optionId(index) === activeOptionId, children: item }, index))) }) })), showCounter && jsxRuntime.jsx("small", { className: counterClasses, children: counterText }), name &&
|
|
13265
13296
|
tags.map((tag, i) => (jsxRuntime.jsx("input", { type: "hidden", name: name, value: getDisplayValue(tag), form: form }, `tag-input-${i}`)))] }));
|
|
13266
13297
|
if (ownField) {
|
|
13267
13298
|
return (jsxRuntime.jsxs(Field, { label: label, labelSize: labelSize, labelProps: fieldLabelProps, horizontal: horizontal, className: fieldClassName, children: [taginputElement, messageEl] }));
|