Skip to content

Commit

Permalink
Revert "Components: FormTokenField - add prop to allow saving of toke…
Browse files Browse the repository at this point in the history
…ns onBlur
  • Loading branch information
glendaviesnz committed Sep 14, 2023
1 parent 4d14b0f commit 1ad421b
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 49 deletions.
1 change: 0 additions & 1 deletion packages/components/src/form-token-field/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ The `value` property is handled in a manner similar to controlled form component
- `__experimentalValidateInput` - If passed, all introduced values will be validated before being added as tokens.
- `__experimentalAutoSelectFirstMatch` - If true, the select the first matching suggestion when the user presses the Enter key (or space when tokenizeOnSpace is true).
- `__nextHasNoMarginBottom` - Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.5. (The prop can be safely removed once this happens.)
- `tokenizeOnBlur` - If true, add any incompleteTokenValue as a new token when the field loses focus.

## Usage

Expand Down
6 changes: 1 addition & 5 deletions packages/components/src/form-token-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export function FormTokenField( props: FormTokenFieldProps ) {
__next40pxDefaultSize = false,
__experimentalAutoSelectFirstMatch = false,
__nextHasNoMarginBottom = false,
tokenizeOnBlur = false,
} = useDeprecated36pxDefaultSizeProp< FormTokenFieldProps >(
props,
'wp.components.FormTokenField'
Expand Down Expand Up @@ -168,9 +167,6 @@ export function FormTokenField( props: FormTokenFieldProps ) {
__experimentalValidateInput( incompleteTokenValue )
) {
setIsActive( false );
if ( tokenizeOnBlur && inputHasValidValue() ) {
addNewToken( incompleteTokenValue );
}
} else {
// Reset to initial state
setIncompleteTokenValue( '' );
Expand Down Expand Up @@ -455,7 +451,7 @@ export function FormTokenField( props: FormTokenFieldProps ) {
setSelectedSuggestionScroll( false );
setIsExpanded( ! __experimentalExpandOnFocus );

if ( isActive && ! tokenizeOnBlur ) {
if ( isActive ) {
focus();
}
}
Expand Down
37 changes: 1 addition & 36 deletions packages/components/src/form-token-field/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,42 +205,7 @@ describe( 'FormTokenField', () => {
] );
} );

it( 'should add a token with the input value with onBlur when `tokenizeOnBlur` prop is `true`', async () => {
const user = userEvent.setup();

const onChangeSpy = jest.fn();

const { rerender } = render(
<FormTokenFieldWithState onChange={ onChangeSpy } />
);

const input = screen.getByRole( 'combobox' );

// Add 'grapefruit' token by typing it and check blur of field does not tokenize it.
await user.type( input, 'grapefruit' );
await user.click( document.body );
expect( onChangeSpy ).toHaveBeenCalledTimes( 0 );
expectTokensNotToBeInTheDocument( [ 'grapefruit' ] );

rerender(
<FormTokenFieldWithState
onChange={ onChangeSpy }
tokenizeOnBlur
/>
);
await user.clear( input );

// Add 'grapefruit' token by typing it and check blur of field tokenizes it.
await user.type( input, 'grapefruit' );

await user.click( document.body );
expect( onChangeSpy ).toHaveBeenNthCalledWith( 1, [
'grapefruit',
] );
expectTokensToBeInTheDocument( [ 'grapefruit' ] );
} );

it( "should not add a token with the input's value when tokenizeOnBlur is not set and pressing the tab key", async () => {
it( "should not add a token with the input's value when pressing the tab key", async () => {
const user = userEvent.setup();

const onChangeSpy = jest.fn();
Expand Down
6 changes: 0 additions & 6 deletions packages/components/src/form-token-field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ export interface FormTokenFieldProps
* @default false
*/
__nextHasNoMarginBottom?: boolean;
/**
* If true, add any incompleteTokenValue as a new token when the field loses focus.
*
* @default false
*/
tokenizeOnBlur?: boolean;
}

/**
Expand Down
1 change: 0 additions & 1 deletion packages/patterns/src/components/category-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export default function CategorySelector( { onCategorySelection } ) {
onInputChange={ debouncedSearch }
maxSuggestions={ MAX_TERMS_SUGGESTIONS }
label={ __( 'Categories' ) }
tokenizeOnBlur={ true }
/>
</>
);
Expand Down

0 comments on commit 1ad421b

Please sign in to comment.