-
Notifications
You must be signed in to change notification settings - Fork 4.7k
form-token-field/TokenInput: Fix automatic focus on first render due to updating selected value from async stores #44347
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
Changes from all commits
7706fa2
819fe4d
5a36188
6177023
e1b450a
885c304
e67f319
1852c29
98e96e7
3f2aff7
dab608d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,11 +247,7 @@ function ComboboxControl( { | |
| instanceId={ instanceId } | ||
| ref={ inputContainer } | ||
| value={ isExpanded ? inputValue : currentLabel } | ||
| aria-label={ | ||
| currentLabel | ||
| ? `${ currentLabel }, ${ label }` | ||
| : null | ||
|
Comment on lines
-250
to
-253
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it ok to remove this aria-label, given that we're already using CC'ing @tellthemachines since it looks like she introduced this change in #27431
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ciampo If done right, there is no reason native HTML should not work for this control as suggested by @joedolson in the related issue. Sometimes ARIA complicates things and sometimes it has a really good use. I am not sure how this works for Mac yet as I have not tested it. |
||
| } | ||
| inputHasFocus={ inputHasFocus } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to pass this so I know if input has focus or not. |
||
| onFocus={ onFocus } | ||
| onBlur={ onBlur } | ||
| isExpanded={ isExpanded } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ export function UnForwardedTokenInput( | |
| const { | ||
| value, | ||
| isExpanded, | ||
| inputHasFocus, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gives me the focus of the input field. |
||
| instanceId, | ||
| selectedSuggestionIndex, | ||
| className, | ||
|
|
@@ -30,6 +31,9 @@ export function UnForwardedTokenInput( | |
| } = props; | ||
|
|
||
| const size = value ? value.length + 1 : 0; | ||
| // Ensure this is set to true if inputHasFocus is not defined. | ||
| const checkInputHasFocus = | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not a given that this var will be used for this component. If it is not defined, still allow us to keep same functionality. |
||
| inputHasFocus !== undefined ? inputHasFocus : true; | ||
|
|
||
| const onChangeHandler = ( event: ChangeEvent< HTMLInputElement > ) => { | ||
| if ( onChange ) { | ||
|
|
@@ -62,7 +66,7 @@ export function UnForwardedTokenInput( | |
| : undefined | ||
| } | ||
| aria-activedescendant={ | ||
| selectedSuggestionIndex !== -1 | ||
| checkInputHasFocus && selectedSuggestionIndex !== -1 | ||
| ? `components-form-token-suggestions-${ instanceId }-${ selectedSuggestionIndex }` | ||
| : undefined | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,7 @@ export interface TokenProps extends TokenItem { | |
|
|
||
| export interface TokenInputProps { | ||
| isExpanded: boolean; | ||
| inputHasFocus?: boolean; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is okay to keep this as optional, I just need to add a fallback to handle this if the var does not exist. |
||
| instanceId: string | number; | ||
| selectedSuggestionIndex: number; | ||
| onChange?: ( { value }: { value: string } ) => void; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not need this any longer since
valuedisplays the currently selected option.