Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update defaults to 1) Expand on focus, and 2) validate inputs in arra…
…y only
  • Loading branch information
elazzabi committed Aug 11, 2025
commit f48d7e0785a7e56b4119045360e15580f09ab6b2
18 changes: 5 additions & 13 deletions packages/dataviews/src/dataform-controls/array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,11 @@ export default function ArrayControl< Item >( {
// Custom validation function for FormTokenField
const validateInput = useCallback(
Copy link
Member

@oandregal oandregal Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the array doesn't provide any elements? Users still need to be able to add values in that case:

Screen.Recording.2025-08-12.at.08.18.55.mov

We have a story for each field type. In the array story, can we add an example of field array without elements to make sure this case is testable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, if there are no elements provided, we could improve the user experience by:

  • not displaying the suggestion list (__experimentalExpandOnFocus)
  • displaying the how to (__experimentalShowHowTo), so users know how to interact with the component

( token: string ) => {
if ( field.isValid?.custom ) {
const testValue = [ ...arrayValue, token ];
const validationResult = field.isValid.custom(
{
...data,
[ id ]: testValue,
},
field
);
return validationResult === null;
}
return true;
return !! elements?.some( ( element ) => {
return element.label === token;
} );
},
[ field, data, id, arrayValue ]
[ elements ]
);

return (
Expand All @@ -92,6 +83,7 @@ export default function ArrayControl< Item >( {
elements?.map( ( suggestion ) => suggestion.label ) ?? []
}
__experimentalValidateInput={ validateInput }
__experimentalExpandOnFocus
__next40pxDefaultSize
__nextHasNoMarginBottom
{ ...extraProps }
Expand Down
Loading