Skip to content

Commit

Permalink
Disabled control for __experimentalValidateInput. Update type document.
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Jun 1, 2022
1 parent edb5402 commit af8adec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
14 changes: 1 addition & 13 deletions packages/components/src/form-token-field/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const meta: ComponentMeta< typeof FormTokenField > = {
control: { type: null },
},
__experimentalValidateInput: {
control: { type: 'boolean' },
control: { type: null },
},
},
parameters: {
Expand All @@ -43,7 +43,6 @@ const continents = [
];

const DefaultTemplate: ComponentStory< typeof FormTokenField > = ( {
__experimentalValidateInput,
...args
} ) => {
const [ selectedContinents, setSelectedContinents ] = useState<
Expand All @@ -55,11 +54,6 @@ const DefaultTemplate: ComponentStory< typeof FormTokenField > = ( {
{ ...args }
value={ selectedContinents }
onChange={ ( tokens ) => setSelectedContinents( tokens ) }
__experimentalValidateInput={
__experimentalValidateInput
? ( newValue ) => continents.includes( newValue )
: () => true
}
/>
);
};
Expand All @@ -73,7 +67,6 @@ Default.args = {
};

export const Async: ComponentStory< typeof FormTokenField > = ( {
__experimentalValidateInput,
suggestions,
...args
} ) => {
Expand Down Expand Up @@ -102,11 +95,6 @@ export const Async: ComponentStory< typeof FormTokenField > = ( {
suggestions={ availableContinents }
onChange={ ( tokens ) => setSelectedContinents( tokens ) }
onInputChange={ searchContinents }
__experimentalValidateInput={
__experimentalValidateInput
? ( newValue ) => continents.includes( newValue )
: () => true
}
/>
);
};
Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/form-token-field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ export interface FormTokenFieldProps
* - otherwise entities like `&` in tag names are double-encoded like `&amp;`,
* once by the REST API and once by React).
*/
displayTransform?: ( suggestion: string ) => string;
displayTransform?: ( token: string ) => string;
/**
* Function to call to transform tokens for saving. The default is to trim the token value.
* This function is also applied when matching suggestions against the current value
* so that matching works correctly with leading or trailing spaces. (In the editor,
* this is needed to remove leading and trailing spaces from tag names, like wp-admin does.
* Otherwise the REST API won't save them.)
*
* @default ( token: string ) => token.trim()
*/
saveTransform?: ( token: string ) => string;
/**
Expand Down Expand Up @@ -136,6 +137,8 @@ export interface FormTokenFieldProps
__experimentalExpandOnFocus?: boolean;
/**
* If passed, all introduced values will be validated before being added as tokens.
*
* @default () => true
*/
__experimentalValidateInput?: ( token: string ) => boolean;
/**
Expand Down

0 comments on commit af8adec

Please sign in to comment.