Skip to content
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

Add component support for suggestion for FormTokenField #42150

Open
dinhtungdu opened this issue Jul 5, 2022 · 1 comment
Open

Add component support for suggestion for FormTokenField #42150

dinhtungdu opened this issue Jul 5, 2022 · 1 comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.

Comments

@dinhtungdu
Copy link
Contributor

What problem does this address?

In the <FormTokenField> component, the return type of displayTransform is expected to be a string. But in fact, we can return a component to display complex suggestions lists like the screenshot below.

image

When returning a component for displayTransform, we have an issue with the <Token> component:

const transformedValue = displayTransform( value );
const termPositionAndCount = sprintf(
/* translators: 1: term name, 2: term position in a set of terms, 3: total term set count. */
__( '%1$s (%2$s of %3$s)' ),
transformedValue,
termPosition,
termsCount
);

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 or listDisplayTransform with the default value to the displayTransform 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.

@kathrynwp kathrynwp added Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Jul 11, 2022
@mirka
Copy link
Member

mirka commented Jul 12, 2022

For what it's worth, we are starting to explore (#41466) a more composable API for this family of components, which should allow use cases like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants