-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(autocomplete): return value instead of label in form submission #3375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c203bcb
feat(autocomplete): exclude name in input and add getHiddenInputProps
wingkwong 36c38df
Merge branch 'canary' into fix/eng-1067
wingkwong 049c1bd
fix(autocomplete): revise getInputProps logic
wingkwong cde7cad
feat(autocomplete): hidden input
wingkwong db33506
feat(autocomplete): include HiddenInput in autocomplete
wingkwong 4f44322
feat(changeset): add changeset
wingkwong 4144d44
fix(autocomplete): set empty string by default for value
wingkwong e95d528
fix(autocomplete): avoid passing custom attribute to DOM
wingkwong e137507
fix(autocomplete): props comments
wingkwong e8c4149
feat(autocomplete): include @react-aria/form
wingkwong 64599e7
feat(autocomplete): add inputData map for hidden input
wingkwong 91f4c5a
feat(autocomplete): useHiddenInput
wingkwong 455f985
chore(deps): pnpm-lock.yaml
wingkwong f29fc26
Merge branch 'canary' into fix/eng-1067
wingkwong 018cb53
fix(autocomplete): add missing import
wingkwong e02d9c7
feat(autocomplete): add WithFormTemplate
wingkwong c8b45a8
Merge branch 'canary' into fix/eng-1067
wingkwong 3fb677e
Merge branch 'canary' into fix/eng-1067
wingkwong caa14e8
fix(autocomplete): include onSelectionChange logic and add missing on…
wingkwong 737ad50
chore(autocomplete): remove duplicate dependency
wingkwong ae5940c
refactor(autocomplete): remove props
wingkwong 313119d
Merge branch 'canary' into fix/eng-1067
wingkwong fe8dc2f
feat(autocomplete): include hiddenInputRef
wingkwong 853e3dd
feat(autocomplete): include hiddenInputRef logic
wingkwong ea8894a
feat(autocomplete): add test case
wingkwong a0a7042
fix(autocomplete): typing on onSelectionChange
wingkwong f8cce31
fix(autocomplete): handle allowsCustomValue
wingkwong 1a84b7b
chore(autocomplete): add default values
wingkwong 8ee75de
fix(autocomplete): pr comments
wingkwong 5eaf174
refactor(autocomplete): add hiddenInputRef.current check
wingkwong 4407700
Merge branch 'beta/release-next' into fix/eng-1067
wingkwong 0f71b97
Update .changeset/purple-pillows-beg.md
jrgarciadev 09bcf2b
Merge branch 'beta/release-next' into fix/eng-1067
wingkwong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@nextui-org/autocomplete": patch | ||
| --- | ||
|
|
||
| return autocomplete value instead of label in form submission (#3353, #3343) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import type {ComboBoxState} from "@react-stately/combobox"; | ||
|
|
||
| import React, {ReactNode, RefObject} from "react"; | ||
| import {useFormReset} from "@react-aria/utils"; | ||
| import {useFormValidation} from "@react-aria/form"; | ||
|
|
||
| import {inputData} from "./use-autocomplete"; | ||
|
|
||
| export interface AriaHiddenInputProps { | ||
| /** | ||
| * Describes the type of autocomplete functionality the input should provide if any. | ||
| * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). | ||
| */ | ||
| autoComplete?: string; | ||
| /** The text label for the input. */ | ||
| label?: ReactNode; | ||
| /** HTML form input name. */ | ||
| name?: string; | ||
| /** Sets the disabled state of the input. */ | ||
| isDisabled?: boolean; | ||
| /** Whether the input is required. */ | ||
| isRequired?: boolean; | ||
| } | ||
|
|
||
| type NativeHTMLInputProps = Omit< | ||
| React.InputHTMLAttributes<HTMLInputElement>, | ||
| keyof AriaHiddenInputProps | ||
| >; | ||
|
|
||
| type CombinedAriaInputProps = NativeHTMLInputProps & AriaHiddenInputProps; | ||
|
|
||
| export interface HiddenInputProps<T> extends CombinedAriaInputProps { | ||
| /** State for the input. */ | ||
| state: ComboBoxState<T>; | ||
| /** A ref to the hidden `<input>` element. */ | ||
| hiddenInputRef?: RefObject<HTMLInputElement>; | ||
| /** A ref to the `<input>` element. */ | ||
| inputRef?: RefObject<HTMLInputElement>; | ||
| } | ||
|
|
||
| export function useHiddenInput<T>(props: HiddenInputProps<T>) { | ||
| const data = inputData.get(props.state) || {}; | ||
|
|
||
| const { | ||
| state, | ||
| autoComplete, | ||
| name = data.name, | ||
| isDisabled = data.isDisabled, | ||
| hiddenInputRef, | ||
| inputRef, | ||
| onChange, | ||
| } = props; | ||
|
|
||
| const {validationBehavior, isRequired} = data; | ||
|
|
||
| useFormReset(inputRef!, state.selectedKey, state.setSelectedKey); | ||
| useFormValidation( | ||
| { | ||
| validationBehavior, | ||
| focus: () => inputRef?.current?.focus(), | ||
| }, | ||
| state, | ||
| inputRef, | ||
| ); | ||
|
|
||
| return { | ||
| name, | ||
| ref: hiddenInputRef, | ||
| type: "hidden", | ||
| disabled: isDisabled, | ||
| required: isRequired, | ||
| autoComplete, | ||
| value: state.selectedKey ?? inputRef?.current?.value ?? "", | ||
| onChange: (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| state.setSelectedKey(e.target.value); | ||
| onChange?.(e); | ||
| }, | ||
| }; | ||
| } | ||
|
wingkwong marked this conversation as resolved.
|
||
|
|
||
| export function HiddenInput<T>(props: HiddenInputProps<T>) { | ||
| const inputProps = useHiddenInput(props); | ||
|
|
||
| return <input {...inputProps} />; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.