@neo4j-ndl/react 5.6.4 → 5.7.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/lib/cjs/icons/index.js +1 -1
- package/lib/cjs/index.js +4 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/next/tree-view/TreeView.js +5 -5
- package/lib/cjs/next/tree-view/TreeView.js.map +1 -1
- package/lib/cjs/search-field/SearchField.js +94 -0
- package/lib/cjs/search-field/SearchField.js.map +1 -0
- package/lib/cjs/search-field/index.js +30 -0
- package/lib/cjs/search-field/index.js.map +1 -0
- package/lib/cjs/text-input/TextInput.js +1 -1
- package/lib/cjs/text-input/TextInput.js.map +1 -1
- package/lib/esm/icons/index.mjs +1 -1
- package/lib/esm/index.mjs +4 -3
- package/lib/esm/index.mjs.map +1 -1
- package/lib/esm/next/tree-view/TreeView.mjs +5 -5
- package/lib/esm/next/tree-view/TreeView.mjs.map +1 -1
- package/lib/esm/search-field/SearchField.mjs +89 -0
- package/lib/esm/search-field/SearchField.mjs.map +1 -0
- package/lib/esm/search-field/index.mjs +24 -0
- package/lib/esm/search-field/index.mjs.map +1 -0
- package/lib/esm/text-input/TextInput.mjs +1 -1
- package/lib/esm/text-input/TextInput.mjs.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/search-field/SearchField.d.ts +52 -0
- package/lib/types/search-field/SearchField.d.ts.map +1 -0
- package/lib/types/search-field/index.d.ts +22 -0
- package/lib/types/search-field/index.d.ts.map +1 -0
- package/package.json +7 -2
- package/skills/ndl-react/SKILL.md +3 -2
- package/skills/ndl-react/components/search-field.md +254 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/search-field/index.ts
|
|
2
|
+
/*!
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) "Neo4j"
|
|
5
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
6
|
+
*
|
|
7
|
+
* This file is part of Neo4j.
|
|
8
|
+
*
|
|
9
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU General Public License as published by
|
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
+
* (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* This program is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU General Public License
|
|
20
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
+
*/
|
|
22
|
+
export { SearchField } from "./SearchField.mjs";
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/search-field/index.ts"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport * from './SearchField';\n"],"mappings":""}
|
|
@@ -75,7 +75,7 @@ const TextInput = (_ref) => {
|
|
|
75
75
|
state: value !== null && value !== void 0 ? value : ""
|
|
76
76
|
});
|
|
77
77
|
const hintId = useId();
|
|
78
|
-
const canClear = isClearable && isDisabled !== true;
|
|
78
|
+
const canClear = isClearable && isDisabled !== true && isReadOnly !== true;
|
|
79
79
|
const shouldRenderHint = canClear || isLoading;
|
|
80
80
|
const { field, controlProps } = useFormField({
|
|
81
81
|
errorText,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.mjs","names":[],"sources":["../../../src/text-input/TextInput.tsx"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport {\n type InputHTMLAttributes,\n type ReactElement,\n type ReactNode,\n useId,\n useMemo,\n} from 'react';\n\nimport {\n FormFieldLabel,\n FormFieldMessage,\n useFormField,\n} from '../_common/form-control';\nimport { customLabelAndNoAriaLabelWarningMessage } from '../_common/messages';\nimport { type CommonProps, type TooltipObjectProps } from '../_common/types';\nimport { useSemiControlledInput } from '../_common/use-semi-controlled-input';\nimport { needleWarningMessage } from '../_common/utils';\nimport { XMarkIconOutline } from '../icons/generated/heroIcons/XMarkIconOutline';\nimport { LoadingSpinner } from '../loading-spinner';\nimport { Skeleton } from '../skeleton';\n\n/**\n * @remarks\n * When `moreInformationText` is provided, a tooltip is rendered next to the label, and the `tooltipProps` prop is used to configure the tooltip. The `TooltipObjectProps` type is defined as: `{ root?: Partial<React.ComponentProps<typeof Tooltip>>; trigger?: Partial<React.ComponentProps<typeof Tooltip.Trigger>>; content?: Partial<React.ComponentProps<typeof Tooltip.Content>>; }`, see the Tooltip component for more details.\n *\n * @remarks\n * When `isSkeletonLoading` is true, the input is rendered as a loading skeleton and the `skeletonProps` prop is used to configure the skeleton. For more information, see the Skeleton documentation.\n */\ntype TextInputProps = {\n /** Assistive text displayed below the input */\n helpText?: string | ReactNode;\n\n /** Error message displayed below the input. When provided, it overrides `helpText` and shows an error icon */\n errorText?: string | ReactNode;\n\n /** Leading element rendered inside the input */\n leadingElement?: ReactElement;\n\n /** Trailing element rendered inside the input */\n trailingElement?: ReactElement;\n\n /** Size of the input */\n size?: 'small' | 'medium' | 'large';\n\n /** Whether the input is read-only */\n isReadOnly?: boolean;\n\n /**\n * Whether to display the Required/Optional label next to the field label.\n * Shows Required if isRequired is true, otherwise shows Optional.\n * @default false\n */\n // TODO: inconsistent naming. The same switch is `hasRequiredIndicator` on\n // Combobox and on the internal form control this maps onto, and `isOptional`\n // on TextArea. The name also needs the disable below, which a name using one\n // of the allowed boolean prefixes would not.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n showRequiredOrOptionalLabel?: boolean;\n\n /** Whether the input is disabled */\n isDisabled?: boolean;\n\n /** Whether the input is required */\n isRequired?: boolean;\n\n /** The current value of the input */\n value?: React.ComponentPropsWithoutRef<'input'>['value'];\n\n /** Placeholder text displayed when the input is empty */\n placeholder?: React.ComponentPropsWithoutRef<'input'>['placeholder'];\n\n /** Callback function triggered when the input value changes */\n onChange?: React.ComponentPropsWithoutRef<'input'>['onChange'];\n\n /** Whether the input should take the full available width */\n isFluid?: boolean;\n\n /** Text displayed in the information tooltip shown next to the label */\n moreInformationText?: React.ReactNode;\n\n // TODO v5: inconsistent naming. Every form control names itself differently:\n // the label is optional here and a design with no room for it reaches for\n // htmlAttributes['aria-label'], TextArea, Select, Checkbox, Radio and Switch\n // expose an `ariaLabel` prop instead, and Combobox requires the label and\n // clips it with `hasVisuallyHiddenLabel`.\n /** The label displayed above the input */\n label?: string | React.ReactNode;\n\n /** Props for the Tooltip component used by the information icon */\n tooltipProps?: TooltipObjectProps;\n\n /** Whether to render skeletons instead of content */\n isSkeletonLoading?: boolean;\n\n /** Additional props forwarded to the underlying Skeleton components */\n skeletonProps?: React.ComponentProps<typeof Skeleton>;\n\n /** Whether to show the clear button */\n isClearable?: boolean;\n\n /** Whether to show the loading spinner */\n isLoading?: boolean;\n};\n\n/**\n *\n *\n * TextInput Component\n *\n *\n */\n\nexport const TextInput = ({\n label,\n isFluid,\n errorText,\n helpText,\n leadingElement,\n trailingElement,\n showRequiredOrOptionalLabel = false,\n moreInformationText,\n size = 'medium',\n placeholder,\n value,\n tooltipProps,\n htmlAttributes,\n isDisabled,\n isReadOnly,\n isRequired,\n onChange,\n isClearable = false,\n className,\n style,\n isSkeletonLoading = false,\n isLoading = false,\n skeletonProps,\n ref,\n ...restProps\n}: CommonProps<'input', TextInputProps>) => {\n const [currentValue, handleChange] = useSemiControlledInput({\n inputType: 'text',\n isControlled: value !== undefined,\n onChange,\n state: value ?? '',\n });\n const hintId = useId();\n const canClear = isClearable && isDisabled !== true;\n const shouldRenderHint = canClear || isLoading;\n const { field, controlProps } = useFormField({\n errorText,\n // The clear/loading hint describes the input alongside the message.\n extraDescribedByIds: [shouldRenderHint && hintId],\n hasRequiredIndicator: showRequiredOrOptionalLabel,\n helpText,\n isRequired,\n label,\n });\n\n const containerWrappingClasses = classNames(`ndl-text-input`, className, {\n 'ndl-disabled': isDisabled,\n 'ndl-has-error': errorText,\n 'ndl-has-icon': leadingElement || trailingElement || errorText,\n 'ndl-has-leading-icon': leadingElement,\n 'ndl-has-trailing-icon': trailingElement || errorText,\n 'ndl-large': size === 'large',\n 'ndl-medium': size === 'medium',\n 'ndl-read-only': isReadOnly,\n 'ndl-small': size === 'small',\n });\n\n const hasEmptyLabelValue =\n label === undefined || label === null || label === '';\n\n const labelWrappingClasses = classNames('ndl-text-input-label', {\n 'ndl-fluid': isFluid,\n });\n\n const combinedHtmlInputAttributes: InputHTMLAttributes<HTMLInputElement> = {\n ...htmlAttributes,\n className: classNames('ndl-input', htmlAttributes?.className),\n };\n const ariaLabel = combinedHtmlInputAttributes['aria-label'];\n const isCustomLabel = Boolean(label) && typeof label !== 'string';\n const hasCustomLabelAndNoAriaLabel =\n isCustomLabel && (ariaLabel === undefined || ariaLabel === '');\n\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (canClear && event.key === 'Escape' && Boolean(currentValue)) {\n event.preventDefault();\n event.stopPropagation();\n handleChange?.({\n target: { value: '' },\n } as React.ChangeEvent<HTMLInputElement>);\n }\n htmlAttributes?.onKeyDown?.(event);\n };\n\n useMemo(() => {\n if (!label && !ariaLabel) {\n needleWarningMessage(\n 'A TextInput without a label does not have an aria label, be sure to include an aria label for screen readers. Link: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI',\n );\n }\n\n if (hasCustomLabelAndNoAriaLabel) {\n needleWarningMessage(customLabelAndNoAriaLabelWarningMessage);\n }\n }, [label, ariaLabel, hasCustomLabelAndNoAriaLabel]);\n\n return (\n <div className={containerWrappingClasses} style={style}>\n {/* We enable implicit label wrapping */}\n {/* Source: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI */}\n <label className={labelWrappingClasses}>\n {!hasEmptyLabelValue && (\n <FormFieldLabel\n field={field}\n size={size}\n association=\"implicit\"\n moreInformationText={moreInformationText}\n tooltipProps={tooltipProps}\n wrap={(row) => (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n {row}\n </Skeleton>\n )}\n />\n )}\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-input-wrapper\">\n {(leadingElement || (isLoading && !trailingElement)) && (\n <div className=\"ndl-element-leading ndl-element\">\n {isLoading ? (\n <LoadingSpinner\n size={size === 'large' ? 'medium' : 'small'}\n className={\n size === 'large'\n ? 'ndl-medium-spinner'\n : 'ndl-small-spinner'\n }\n />\n ) : (\n leadingElement\n )}\n </div>\n )}\n <div\n className={classNames('ndl-input-container', {\n 'ndl-clearable': isClearable,\n })}\n >\n <input\n ref={ref}\n readOnly={isReadOnly}\n disabled={isDisabled}\n required={isRequired}\n value={currentValue}\n placeholder={placeholder}\n type=\"text\"\n onChange={handleChange}\n {...controlProps}\n {...combinedHtmlInputAttributes}\n onKeyDown={handleInputKeyDown}\n {...restProps}\n />\n {shouldRenderHint && (\n <span\n id={hintId}\n className=\"ndl-text-input-hint\"\n aria-hidden={true}\n >\n {isLoading && 'Loading '}\n {canClear && 'Press Escape to clear input.'}\n </span>\n )}\n {canClear && Boolean(currentValue) && (\n <div className=\"ndl-element-clear ndl-element\">\n <button\n tabIndex={-1}\n aria-hidden={true}\n type=\"button\"\n title=\"Clear input (Esc)\"\n onClick={() => {\n handleChange?.({\n target: { value: '' },\n } as React.ChangeEvent<HTMLInputElement>);\n }}\n >\n <XMarkIconOutline />\n </button>\n </div>\n )}\n </div>\n {trailingElement && (\n <div className=\"ndl-element-trailing ndl-element\">\n {isLoading && !leadingElement ? (\n <LoadingSpinner\n size={size === 'large' ? 'medium' : 'small'}\n className={\n size === 'large'\n ? 'ndl-medium-spinner'\n : 'ndl-small-spinner'\n }\n />\n ) : (\n trailingElement\n )}\n </div>\n )}\n </div>\n </Skeleton>\n </label>\n\n <FormFieldMessage\n field={field}\n size={size}\n wrap={(content) => (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n {content}\n </Skeleton>\n )}\n />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuIE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;;AAxBF,MAAa,aAAa,SA0BkB;CA1BlB,IAAA,EACxB,OACA,SACA,WACA,UACA,gBACA,iBACA,8BAA8B,OAC9B,qBACA,OAAO,UACP,aACA,OACA,cACA,gBACA,YACA,YACA,YACA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SACJ,WAAU;SACV,eAAa;SAHf,UAAA,CAKG,aAAa,YACb,YAAY,8BACT;;QAEP,YAAY,QAAQ,YAAY,KAC/B,oBAAC,OAAD;SAAK,WAAU;SACb,UAAA,oBAAC,UAAD;UACE,UAAU;UACV,eAAa;UACb,MAAK;UACL,OAAM;UACN,eAAe;WACb,iBAAA,QAAA,iBAAA,KAAA,KAAA,aAAe,EACb,QAAQ,EAAE,OAAO,GAAG,EACtB,CAAwC;UAC1C;UAEA,UAAA,oBAAC,kBAAD,CAAmB,CAAA;SACb,CAAA;QACL,CAAA;OAEJ;;MACJ,mBACC,oBAAC,OAAD;OAAK,WAAU;OACZ,UAAA,aAAa,CAAC,iBACb,oBAAC,gBAAD;QACE,MAAM,SAAS,UAAU,WAAW;QACpC,WACE,SAAS,UACL,uBACA;OAEP,CAAA,IAED;MAEC,CAAA;KAEJ;;GACG,CAAA,CAAA,CACL;EAEP,CAAA,GAAA,oBAAC,kBAAD;GACS;GACD;GACN,OAAO,YACL,oBAAC,UAAA,eAAA,eAAA;IACC,cAAa;IACb,OAAM;GACF,GAAA,aAAA,GAAA,CAAA,GAAA;IACJ,WAAW;IAEV,UAAA;GACO,CAAA,CAAA;EAEb,CAAA,CACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"TextInput.mjs","names":[],"sources":["../../../src/text-input/TextInput.tsx"],"sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport {\n type InputHTMLAttributes,\n type ReactElement,\n type ReactNode,\n useId,\n useMemo,\n} from 'react';\n\nimport {\n FormFieldLabel,\n FormFieldMessage,\n useFormField,\n} from '../_common/form-control';\nimport { customLabelAndNoAriaLabelWarningMessage } from '../_common/messages';\nimport { type CommonProps, type TooltipObjectProps } from '../_common/types';\nimport { useSemiControlledInput } from '../_common/use-semi-controlled-input';\nimport { needleWarningMessage } from '../_common/utils';\nimport { XMarkIconOutline } from '../icons/generated/heroIcons/XMarkIconOutline';\nimport { LoadingSpinner } from '../loading-spinner';\nimport { Skeleton } from '../skeleton';\n\n/**\n * @remarks\n * When `moreInformationText` is provided, a tooltip is rendered next to the label, and the `tooltipProps` prop is used to configure the tooltip. The `TooltipObjectProps` type is defined as: `{ root?: Partial<React.ComponentProps<typeof Tooltip>>; trigger?: Partial<React.ComponentProps<typeof Tooltip.Trigger>>; content?: Partial<React.ComponentProps<typeof Tooltip.Content>>; }`, see the Tooltip component for more details.\n *\n * @remarks\n * When `isSkeletonLoading` is true, the input is rendered as a loading skeleton and the `skeletonProps` prop is used to configure the skeleton. For more information, see the Skeleton documentation.\n */\ntype TextInputProps = {\n /** Assistive text displayed below the input */\n helpText?: string | ReactNode;\n\n /** Error message displayed below the input. When provided, it overrides `helpText` and shows an error icon */\n errorText?: string | ReactNode;\n\n /** Leading element rendered inside the input */\n leadingElement?: ReactElement;\n\n /** Trailing element rendered inside the input */\n trailingElement?: ReactElement;\n\n /** Size of the input */\n size?: 'small' | 'medium' | 'large';\n\n /** Whether the input is read-only */\n isReadOnly?: boolean;\n\n /**\n * Whether to display the Required/Optional label next to the field label.\n * Shows Required if isRequired is true, otherwise shows Optional.\n * @default false\n */\n // TODO: inconsistent naming. The same switch is `hasRequiredIndicator` on\n // Combobox and on the internal form control this maps onto, and `isOptional`\n // on TextArea. The name also needs the disable below, which a name using one\n // of the allowed boolean prefixes would not.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n showRequiredOrOptionalLabel?: boolean;\n\n /** Whether the input is disabled */\n isDisabled?: boolean;\n\n /** Whether the input is required */\n isRequired?: boolean;\n\n /** The current value of the input */\n value?: React.ComponentPropsWithoutRef<'input'>['value'];\n\n /** Placeholder text displayed when the input is empty */\n placeholder?: React.ComponentPropsWithoutRef<'input'>['placeholder'];\n\n /** Callback function triggered when the input value changes */\n onChange?: React.ComponentPropsWithoutRef<'input'>['onChange'];\n\n /** Whether the input should take the full available width */\n isFluid?: boolean;\n\n /** Text displayed in the information tooltip shown next to the label */\n moreInformationText?: React.ReactNode;\n\n // TODO v5: inconsistent naming. Every form control names itself differently:\n // the label is optional here and a design with no room for it reaches for\n // htmlAttributes['aria-label'], TextArea, Select, Checkbox, Radio and Switch\n // expose an `ariaLabel` prop instead, and Combobox requires the label and\n // clips it with `hasVisuallyHiddenLabel`.\n /** The label displayed above the input */\n label?: string | React.ReactNode;\n\n /** Props for the Tooltip component used by the information icon */\n tooltipProps?: TooltipObjectProps;\n\n /** Whether to render skeletons instead of content */\n isSkeletonLoading?: boolean;\n\n /** Additional props forwarded to the underlying Skeleton components */\n skeletonProps?: React.ComponentProps<typeof Skeleton>;\n\n /** Whether to show the clear button */\n isClearable?: boolean;\n\n /** Whether to show the loading spinner */\n isLoading?: boolean;\n};\n\n/**\n *\n *\n * TextInput Component\n *\n *\n */\n\nexport const TextInput = ({\n label,\n isFluid,\n errorText,\n helpText,\n leadingElement,\n trailingElement,\n showRequiredOrOptionalLabel = false,\n moreInformationText,\n size = 'medium',\n placeholder,\n value,\n tooltipProps,\n htmlAttributes,\n isDisabled,\n isReadOnly,\n isRequired,\n onChange,\n isClearable = false,\n className,\n style,\n isSkeletonLoading = false,\n isLoading = false,\n skeletonProps,\n ref,\n ...restProps\n}: CommonProps<'input', TextInputProps>) => {\n const [currentValue, handleChange] = useSemiControlledInput({\n inputType: 'text',\n isControlled: value !== undefined,\n onChange,\n state: value ?? '',\n });\n const hintId = useId();\n const canClear = isClearable && isDisabled !== true && isReadOnly !== true;\n const shouldRenderHint = canClear || isLoading;\n const { field, controlProps } = useFormField({\n errorText,\n // The clear/loading hint describes the input alongside the message.\n extraDescribedByIds: [shouldRenderHint && hintId],\n hasRequiredIndicator: showRequiredOrOptionalLabel,\n helpText,\n isRequired,\n label,\n });\n\n const containerWrappingClasses = classNames(`ndl-text-input`, className, {\n 'ndl-disabled': isDisabled,\n 'ndl-has-error': errorText,\n 'ndl-has-icon': leadingElement || trailingElement || errorText,\n 'ndl-has-leading-icon': leadingElement,\n 'ndl-has-trailing-icon': trailingElement || errorText,\n 'ndl-large': size === 'large',\n 'ndl-medium': size === 'medium',\n 'ndl-read-only': isReadOnly,\n 'ndl-small': size === 'small',\n });\n\n const hasEmptyLabelValue =\n label === undefined || label === null || label === '';\n\n const labelWrappingClasses = classNames('ndl-text-input-label', {\n 'ndl-fluid': isFluid,\n });\n\n const combinedHtmlInputAttributes: InputHTMLAttributes<HTMLInputElement> = {\n ...htmlAttributes,\n className: classNames('ndl-input', htmlAttributes?.className),\n };\n const ariaLabel = combinedHtmlInputAttributes['aria-label'];\n const isCustomLabel = Boolean(label) && typeof label !== 'string';\n const hasCustomLabelAndNoAriaLabel =\n isCustomLabel && (ariaLabel === undefined || ariaLabel === '');\n\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (canClear && event.key === 'Escape' && Boolean(currentValue)) {\n event.preventDefault();\n event.stopPropagation();\n handleChange?.({\n target: { value: '' },\n } as React.ChangeEvent<HTMLInputElement>);\n }\n htmlAttributes?.onKeyDown?.(event);\n };\n\n useMemo(() => {\n if (!label && !ariaLabel) {\n needleWarningMessage(\n 'A TextInput without a label does not have an aria label, be sure to include an aria label for screen readers. Link: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI',\n );\n }\n\n if (hasCustomLabelAndNoAriaLabel) {\n needleWarningMessage(customLabelAndNoAriaLabelWarningMessage);\n }\n }, [label, ariaLabel, hasCustomLabelAndNoAriaLabel]);\n\n return (\n <div className={containerWrappingClasses} style={style}>\n {/* We enable implicit label wrapping */}\n {/* Source: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI */}\n <label className={labelWrappingClasses}>\n {!hasEmptyLabelValue && (\n <FormFieldLabel\n field={field}\n size={size}\n association=\"implicit\"\n moreInformationText={moreInformationText}\n tooltipProps={tooltipProps}\n wrap={(row) => (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n {row}\n </Skeleton>\n )}\n />\n )}\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-input-wrapper\">\n {(leadingElement || (isLoading && !trailingElement)) && (\n <div className=\"ndl-element-leading ndl-element\">\n {isLoading ? (\n <LoadingSpinner\n size={size === 'large' ? 'medium' : 'small'}\n className={\n size === 'large'\n ? 'ndl-medium-spinner'\n : 'ndl-small-spinner'\n }\n />\n ) : (\n leadingElement\n )}\n </div>\n )}\n <div\n className={classNames('ndl-input-container', {\n 'ndl-clearable': isClearable,\n })}\n >\n <input\n ref={ref}\n readOnly={isReadOnly}\n disabled={isDisabled}\n required={isRequired}\n value={currentValue}\n placeholder={placeholder}\n type=\"text\"\n onChange={handleChange}\n {...controlProps}\n {...combinedHtmlInputAttributes}\n onKeyDown={handleInputKeyDown}\n {...restProps}\n />\n {shouldRenderHint && (\n <span\n id={hintId}\n className=\"ndl-text-input-hint\"\n aria-hidden={true}\n >\n {isLoading && 'Loading '}\n {canClear && 'Press Escape to clear input.'}\n </span>\n )}\n {canClear && Boolean(currentValue) && (\n <div className=\"ndl-element-clear ndl-element\">\n <button\n tabIndex={-1}\n aria-hidden={true}\n type=\"button\"\n title=\"Clear input (Esc)\"\n onClick={() => {\n handleChange?.({\n target: { value: '' },\n } as React.ChangeEvent<HTMLInputElement>);\n }}\n >\n <XMarkIconOutline />\n </button>\n </div>\n )}\n </div>\n {trailingElement && (\n <div className=\"ndl-element-trailing ndl-element\">\n {isLoading && !leadingElement ? (\n <LoadingSpinner\n size={size === 'large' ? 'medium' : 'small'}\n className={\n size === 'large'\n ? 'ndl-medium-spinner'\n : 'ndl-small-spinner'\n }\n />\n ) : (\n trailingElement\n )}\n </div>\n )}\n </div>\n </Skeleton>\n </label>\n\n <FormFieldMessage\n field={field}\n size={size}\n wrap={(content) => (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n {content}\n </Skeleton>\n )}\n />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuIE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;;AAxBF,MAAa,aAAa,SA0BkB;CA1BlB,IAAA,EACxB,OACA,SACA,WACA,UACA,gBACA,iBACA,8BAA8B,OAC9B,qBACA,OAAO,UACP,aACA,OACA,cACA,gBACA,YACA,YACA,YACA,UACA,cAAc,OACd,WACA,OACA,oBAAoB,OACpB,YAAY,OACZ,eACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,CAAC,cAAc,gBAAgB,uBAAuB;EAC1D,WAAW;EACX,cAAc,UAAU,KAAA;EACxB;EACA,OAAO,UAAA,QAAA,UAAA,KAAA,IAAA,QAAS;CAClB,CAAC;CACD,MAAM,SAAS,MAAM;CACrB,MAAM,WAAW,eAAe,eAAe,QAAQ,eAAe;CACtE,MAAM,mBAAmB,YAAY;CACrC,MAAM,EAAE,OAAO,iBAAiB,aAAa;EAC3C;EAEA,qBAAqB,CAAC,oBAAoB,MAAM;EAChD,sBAAsB;EACtB;EACA;EACA;CACF,CAAC;CAED,MAAM,2BAA2B,WAAW,kBAAkB,WAAW;EACvE,gBAAgB;EAChB,iBAAiB;EACjB,gBAAgB,kBAAkB,mBAAmB;EACrD,wBAAw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,CAAA,CACL;EAEP,CAAA,GAAA,oBAAC,kBAAD;GACS;GACD;GACN,OAAO,YACL,oBAAC,UAAA,eAAA,eAAA;IACC,cAAa;IACb,OAAM;GACF,GAAA,aAAA,GAAA,CAAA,GAAA;IACJ,WAAW;IAEV,UAAA;GACO,CAAA,CAAA;EAEb,CAAA,CACE;;AAET"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export { ProgressBar } from './progress-bar';
|
|
|
39
39
|
export { Dropzone } from './dropzone';
|
|
40
40
|
export * from './data-grid';
|
|
41
41
|
export { TextInput } from './text-input';
|
|
42
|
+
export { SearchField } from './search-field';
|
|
42
43
|
export { TextArea } from './text-area';
|
|
43
44
|
export { TextLink } from './text-link';
|
|
44
45
|
export { Select } from './select';
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,C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kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Neo4j.
|
|
7
|
+
*
|
|
8
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
import { type ComponentProps } from 'react';
|
|
22
|
+
import { TextInput } from '../text-input';
|
|
23
|
+
type SearchFieldTextInputProps = Pick<ComponentProps<typeof TextInput>, 'className' | 'errorText' | 'helpText' | 'htmlAttributes' | 'isDisabled' | 'isFluid' | 'isLoading' | 'isReadOnly' | 'isSkeletonLoading' | 'onChange' | 'placeholder' | 'ref' | 'size' | 'skeletonProps' | 'style' | 'value'>;
|
|
24
|
+
export type SearchFieldProps = SearchFieldTextInputProps & {
|
|
25
|
+
/**
|
|
26
|
+
* Accessible name for the search field. The label is announced by assistive
|
|
27
|
+
* technologies but is not rendered visually.
|
|
28
|
+
*/
|
|
29
|
+
label: string;
|
|
30
|
+
/**
|
|
31
|
+
* Called with the search query after typing pauses for `debounceDelay`, and
|
|
32
|
+
* immediately when the user presses Enter or clears the field.
|
|
33
|
+
*/
|
|
34
|
+
onSearch?: (query: string) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Delay in milliseconds before calling `onSearch` after the query changes.
|
|
37
|
+
* @default 500
|
|
38
|
+
*/
|
|
39
|
+
debounceDelay?: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A text input for entering search queries.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* SearchField renders a fixed search icon and uses the native `search` input
|
|
46
|
+
* type. `onChange` is called immediately, while `onSearch` is debounced until
|
|
47
|
+
* typing pauses. Pressing Enter or clearing the field calls `onSearch`
|
|
48
|
+
* immediately.
|
|
49
|
+
*/
|
|
50
|
+
export declare const SearchField: ({ debounceDelay, htmlAttributes, label, onChange, onSearch, ...textInputProps }: SearchFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=SearchField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchField.d.ts","sourceRoot":"","sources":["../../../src/search-field/SearchField.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAoB,KAAK,cAAc,EAAe,MAAM,OAAO,CAAC;AAI3E,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,KAAK,yBAAyB,GAAG,IAAI,CACnC,cAAc,CAAC,OAAO,SAAS,CAAC,EAC9B,WAAW,GACX,WAAW,GACX,UAAU,GACV,gBAAgB,GAChB,YAAY,GACZ,SAAS,GACT,WAAW,GACX,YAAY,GACZ,mBAAmB,GACnB,UAAU,GACV,aAAa,GACb,KAAK,GACL,MAAM,GACN,eAAe,GACf,OAAO,GACP,OAAO,CACV,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,yBAAyB,GAAG;IACzD;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEnC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GAAI,iFAOzB,gBAAgB,4CAsDlB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Neo4j.
|
|
7
|
+
*
|
|
8
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
export * from './SearchField';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/search-field/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-ndl/react",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React implementation of Neo4j Design System",
|
|
6
6
|
"keywords": [
|
|
@@ -252,6 +252,11 @@
|
|
|
252
252
|
"require": "./lib/cjs/read-only-tag/index.js",
|
|
253
253
|
"import": "./lib/esm/read-only-tag/index.mjs"
|
|
254
254
|
},
|
|
255
|
+
"./search-field": {
|
|
256
|
+
"types": "./lib/types/search-field/index.d.ts",
|
|
257
|
+
"require": "./lib/cjs/search-field/index.js",
|
|
258
|
+
"import": "./lib/esm/search-field/index.mjs"
|
|
259
|
+
},
|
|
255
260
|
"./segmented-control": {
|
|
256
261
|
"types": "./lib/types/segmented-control/index.d.ts",
|
|
257
262
|
"require": "./lib/cjs/segmented-control/index.js",
|
|
@@ -429,7 +434,7 @@
|
|
|
429
434
|
"@tanstack/react-table": "8.21.3",
|
|
430
435
|
"react": ">=19.0.0",
|
|
431
436
|
"react-dom": ">=19.0.0",
|
|
432
|
-
"@neo4j-ndl/base": "^5.4.
|
|
437
|
+
"@neo4j-ndl/base": "^5.4.4"
|
|
433
438
|
},
|
|
434
439
|
"dependencies": {
|
|
435
440
|
"@dnd-kit/core": "6.3.1",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: ndl-react
|
|
3
3
|
metadata:
|
|
4
4
|
package: '@neo4j-ndl/react'
|
|
5
|
-
version: '5.
|
|
5
|
+
version: '5.7.1'
|
|
6
6
|
description: >-
|
|
7
7
|
Build and edit UI with the Neo4j Needle React design system
|
|
8
8
|
(@neo4j-ndl/react). Use when adding, composing, or modifying Needle components
|
|
@@ -15,7 +15,7 @@ description: >-
|
|
|
15
15
|
|
|
16
16
|
# Neo4j Needle (@neo4j-ndl/react)
|
|
17
17
|
|
|
18
|
-
> 📌 Shipped with `@neo4j-ndl/react` v5.
|
|
18
|
+
> 📌 Shipped with `@neo4j-ndl/react` v5.7.1. Once installed into your repo (e.g. via
|
|
19
19
|
> `npx skills add`) this folder is detached from the package — the installed
|
|
20
20
|
> package (TypeScript types in `node_modules/@neo4j-ndl/react`) is the source of
|
|
21
21
|
> truth.
|
|
@@ -184,6 +184,7 @@ Import from `@neo4j-ndl/react`.
|
|
|
184
184
|
| `Radio` | [components/radio.md](components/radio.md) | ✅ | 7 |
|
|
185
185
|
| `RadioGroup` | [components/radio-group.md](components/radio-group.md) | ✅ | 8 |
|
|
186
186
|
| `ReadOnlyTag` | [components/read-only-tag.md](components/read-only-tag.md) | | 4 |
|
|
187
|
+
| `SearchField` | [components/search-field.md](components/search-field.md) | ✅ | 3 |
|
|
187
188
|
| `SegmentedControl` | [components/segmented-control.md](components/segmented-control.md) | ✅ | 5 |
|
|
188
189
|
| `Select` | [components/select.md](components/select.md) | | 14 |
|
|
189
190
|
| `SelectIconButton` | [components/select-icon-button.md](components/select-icon-button.md) | | 4 |
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
[//]: # (This file is auto-generated by the docs:generate-skills script, do not edit it manually)
|
|
2
|
+
|
|
3
|
+
# SearchField
|
|
4
|
+
|
|
5
|
+
Import: `import { SearchField } from '@neo4j-ndl/react'`
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
### SearchField
|
|
10
|
+
|
|
11
|
+
| Prop | Type | Required | Default | Description |
|
|
12
|
+
|------|------|----------|---------|-------------|
|
|
13
|
+
| `debounceDelay` | `number` | | `500` | Delay in milliseconds before calling `onSearch` after the query changes. |
|
|
14
|
+
| `errorText` | `ReactNode` | | | Error message displayed below the input. When provided, it overrides `helpText` and shows an error icon |
|
|
15
|
+
| `helpText` | `ReactNode` | | | Assistive text displayed below the input |
|
|
16
|
+
| `isDisabled` | `boolean` | | | Whether the input is disabled |
|
|
17
|
+
| `isFluid` | `boolean` | | | Whether the input should take the full available width |
|
|
18
|
+
| `isLoading` | `boolean` | | | Whether to show the loading spinner |
|
|
19
|
+
| `isReadOnly` | `boolean` | | | Whether the input is read-only |
|
|
20
|
+
| `isSkeletonLoading` | `boolean` | | | Whether to render skeletons instead of content |
|
|
21
|
+
| `label` | `string` | ✅ | | Accessible name for the search field. The label is announced by assistive technologies but is not rendered visually. |
|
|
22
|
+
| `onChange` | `ChangeEventHandler<HTMLInputElement, HTMLInputElement>` | | | Callback function triggered when the input value changes |
|
|
23
|
+
| `onSearch` | `((query: string) => void)` | | | Called with the search query after typing pauses for `debounceDelay`, and immediately when the user presses Enter or clears the field. |
|
|
24
|
+
| `placeholder` | `string` | | | Placeholder text displayed when the input is empty |
|
|
25
|
+
| `ref` | `Ref<HTMLInputElement>` | | | A ref to apply to the root element. |
|
|
26
|
+
| `size` | `'large' \| 'medium' \| 'small'` | | | Size of the input |
|
|
27
|
+
| `skeletonProps` | `(SkeletonProps & { as?: ElementType<any, keyof IntrinsicElements>; } & BaseProps<ElementType<any, keyof IntrinsicElements>>)` | | | Additional props forwarded to the underlying Skeleton components |
|
|
28
|
+
| `value` | `string \| number \| readonly string[]` | | | The current value of the input |
|
|
29
|
+
|
|
30
|
+
SearchField renders a fixed search icon and uses the native `search` input
|
|
31
|
+
type. `onChange` is called immediately, while `onSearch` is debounced until
|
|
32
|
+
typing pauses. Pressing Enter or clearing the field calls `onSearch`
|
|
33
|
+
immediately.
|
|
34
|
+
|
|
35
|
+
## Accessibility
|
|
36
|
+
|
|
37
|
+
## Implementation guidelines
|
|
38
|
+
|
|
39
|
+
### Name and search landmark
|
|
40
|
+
|
|
41
|
+
The required `label` prop provides the search field's accessible name through `aria-label`; it is not displayed visually. Use a concise label that identifies the search scope or purpose, such as “Search documentation” rather than only “Search,” when context is needed. Do not pass a separate `aria-label` through `htmlAttributes`.
|
|
42
|
+
|
|
43
|
+
SearchField uses the native `search` input type and is exposed with the `searchbox` role.
|
|
44
|
+
|
|
45
|
+
Wrap the field in an element with `role="search"` when it provides page- or site-wide search. If a page has multiple search landmarks, give each landmark a distinct accessible name with `aria-label` or `aria-labelledby`.
|
|
46
|
+
|
|
47
|
+
### Results and status messages
|
|
48
|
+
|
|
49
|
+
Present results with appropriate page structure, such as a heading followed by a list of links. Keep focus in the search field when results update; do not automatically move focus into the results. This lets keyboard and screen reader users decide when to navigate to them.
|
|
50
|
+
|
|
51
|
+
Announce the completed result count in a persistent, polite live region, for example, “7 results for Neo4j” or “No results for Neo4j.” A `role="status"` region with `aria-atomic="true"` supports WCAG 2.2 SC 4.1.3 Status Messages (Level AA). Mount the empty status region before a search starts, update only its text, and do not place interactive content inside it.
|
|
52
|
+
|
|
53
|
+
For asynchronous searches, set `aria-busy="true"` on the results container while it is updating and remove it when the update completes. Communicate loading, failure, and recovery without clearing existing results prematurely. Avoid having multiple live regions announce the same update.
|
|
54
|
+
|
|
55
|
+
SearchField is not an autocomplete or combobox. If typing opens a selectable suggestions popup, use Combobox or implement the complete combobox keyboard and ARIA pattern rather than adding only `aria-expanded` to SearchField.
|
|
56
|
+
|
|
57
|
+
### Interaction
|
|
58
|
+
|
|
59
|
+
SearchField is always clearable. Pressing Escape clears a non-empty search field without moving focus. The same action is available with a pointer from the clear button.
|
|
60
|
+
|
|
61
|
+
`onChange` runs immediately so controlled fields can update their visible value as the user types. `onSearch` is debounced while typing, but runs immediately when the field is cleared or the user presses Enter.
|
|
62
|
+
|
|
63
|
+
If a consumer prevents the default Enter key behavior in `htmlAttributes.onKeyDown`, `onSearch` is not called.
|
|
64
|
+
|
|
65
|
+
## Examples
|
|
66
|
+
|
|
67
|
+
### Default
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
|
|
71
|
+
|
|
72
|
+
import { SearchField } from '@neo4j-ndl/react';
|
|
73
|
+
|
|
74
|
+
const Component = () => {
|
|
75
|
+
return <SearchField label="Search" placeholder="Search for something" />;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default Component;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Debounced
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
|
|
85
|
+
|
|
86
|
+
import { SearchField, Typography } from '@neo4j-ndl/react';
|
|
87
|
+
import { useState } from 'react';
|
|
88
|
+
|
|
89
|
+
const Component = () => {
|
|
90
|
+
const [query, setQuery] = useState('');
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div>
|
|
94
|
+
<SearchField
|
|
95
|
+
label="Search"
|
|
96
|
+
placeholder="Search for something"
|
|
97
|
+
onSearch={setQuery}
|
|
98
|
+
/>
|
|
99
|
+
<Typography as="p" variant="body-medium">
|
|
100
|
+
Latest query: {query || 'None'}
|
|
101
|
+
</Typography>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default Component;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Results
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
|
|
113
|
+
|
|
114
|
+
import { SearchField, Typography } from '@neo4j-ndl/react';
|
|
115
|
+
import { useEffect, useState } from 'react';
|
|
116
|
+
|
|
117
|
+
const documentationPages = [
|
|
118
|
+
{
|
|
119
|
+
description: 'Connect an application and run your first query.',
|
|
120
|
+
href: '#getting-started',
|
|
121
|
+
title: 'Getting started',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
description: 'Learn how nodes, relationships, and properties work.',
|
|
125
|
+
href: '#graph-data-model',
|
|
126
|
+
title: 'Graph data model',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
description: 'Read and write graph data with the Cypher query language.',
|
|
130
|
+
href: '#cypher-manual',
|
|
131
|
+
title: 'Cypher manual',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
description: 'Configure drivers, authentication, and connection pooling.',
|
|
135
|
+
href: '#drivers',
|
|
136
|
+
title: 'Neo4j drivers',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
description: 'Deploy and operate Neo4j in production.',
|
|
140
|
+
href: '#operations',
|
|
141
|
+
title: 'Operations manual',
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const Component = () => {
|
|
146
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
147
|
+
const [query, setQuery] = useState<string | null>(null);
|
|
148
|
+
const [resultMessage, setResultMessage] = useState(
|
|
149
|
+
`${documentationPages.length} results`,
|
|
150
|
+
);
|
|
151
|
+
const [results, setResults] = useState(documentationPages);
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (query === null) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setIsLoading(true);
|
|
159
|
+
|
|
160
|
+
const timeout = window.setTimeout(() => {
|
|
161
|
+
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
162
|
+
const nextResults = documentationPages.filter(({ description, title }) =>
|
|
163
|
+
`${title} ${description}`.toLocaleLowerCase().includes(normalizedQuery),
|
|
164
|
+
);
|
|
165
|
+
const querySuffix = query ? ` for ${query}` : '';
|
|
166
|
+
|
|
167
|
+
setResults(nextResults);
|
|
168
|
+
setResultMessage(
|
|
169
|
+
nextResults.length === 0
|
|
170
|
+
? `No results${querySuffix}`
|
|
171
|
+
: `${nextResults.length} ${
|
|
172
|
+
nextResults.length === 1 ? 'result' : 'results'
|
|
173
|
+
}${querySuffix}`,
|
|
174
|
+
);
|
|
175
|
+
setIsLoading(false);
|
|
176
|
+
}, 400);
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
window.clearTimeout(timeout);
|
|
180
|
+
};
|
|
181
|
+
}, [query]);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<main
|
|
185
|
+
style={{
|
|
186
|
+
display: 'grid',
|
|
187
|
+
gap: '24px',
|
|
188
|
+
maxWidth: '640px',
|
|
189
|
+
width: '100%',
|
|
190
|
+
}}
|
|
191
|
+
>
|
|
192
|
+
<div role="search" aria-label="Documentation">
|
|
193
|
+
<SearchField
|
|
194
|
+
label="Search documentation"
|
|
195
|
+
placeholder="Search documentation"
|
|
196
|
+
isLoading={isLoading}
|
|
197
|
+
onSearch={setQuery}
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<section aria-labelledby="search-results-heading">
|
|
202
|
+
<Typography
|
|
203
|
+
as="h2"
|
|
204
|
+
variant="title-3"
|
|
205
|
+
htmlAttributes={{ id: 'search-results-heading' }}
|
|
206
|
+
>
|
|
207
|
+
Documentation
|
|
208
|
+
</Typography>
|
|
209
|
+
<Typography
|
|
210
|
+
as="p"
|
|
211
|
+
variant="body-medium"
|
|
212
|
+
htmlAttributes={{ 'aria-atomic': 'true', role: 'status' }}
|
|
213
|
+
>
|
|
214
|
+
{resultMessage}
|
|
215
|
+
</Typography>
|
|
216
|
+
<div aria-busy={isLoading || undefined}>
|
|
217
|
+
{results.length > 0 ? (
|
|
218
|
+
<ul
|
|
219
|
+
style={{
|
|
220
|
+
display: 'grid',
|
|
221
|
+
gap: '16px',
|
|
222
|
+
listStyle: 'none',
|
|
223
|
+
margin: '16px 0 0',
|
|
224
|
+
padding: 0,
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
{results.map(({ description, href, title }) => (
|
|
228
|
+
<li key={href}>
|
|
229
|
+
<Typography
|
|
230
|
+
as="a"
|
|
231
|
+
variant="body-medium"
|
|
232
|
+
htmlAttributes={{ href }}
|
|
233
|
+
>
|
|
234
|
+
{title}
|
|
235
|
+
</Typography>
|
|
236
|
+
<Typography
|
|
237
|
+
as="p"
|
|
238
|
+
variant="body-small"
|
|
239
|
+
style={{ margin: '4px 0 0' }}
|
|
240
|
+
>
|
|
241
|
+
{description}
|
|
242
|
+
</Typography>
|
|
243
|
+
</li>
|
|
244
|
+
))}
|
|
245
|
+
</ul>
|
|
246
|
+
) : null}
|
|
247
|
+
</div>
|
|
248
|
+
</section>
|
|
249
|
+
</main>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export default Component;
|
|
254
|
+
```
|