Add component support for suggestion for FormTokenField #42150
Labels
Needs Technical Feedback
Needs testing from a developer perspective.
[Package] Components
/packages/components
[Type] Enhancement
A suggestion for improvement.
What problem does this address?
In the
<FormTokenField>
component, the return type ofdisplayTransform
is expected to be a string. But in fact, we can return a component to display complex suggestions lists like the screenshot below.When returning a component for
displayTransform
, we have an issue with the<Token>
component:gutenberg/packages/components/src/form-token-field/token.tsx
Lines 47 to 54 in 59fb859
The transformed value (which is a component) is printed as a string, resulting in the value of
termPositionAndCount
becomes[bbject Object] (1 of 1)
(see screenshot).What is your proposed solution?
We should add a new prop
suggestionDisplayTransform
orlistDisplayTransform
with the default value to thedisplayTransform
value. The new prop is used for the suggestions list only and the return type can be string or component.Additional information
This issue is raised when we try to migrate from a custom dropdown component to
<FormTokenField>
in woocommerce/woocommerce-blocks#3762 and woocommerce/woocommerce-blocks#6647.The text was updated successfully, but these errors were encountered: