WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.25k stars 4.09k forks source link

SelectControl: Add borderless prop #57720

Closed jameskoster closed 1 month ago

jameskoster commented 7 months ago

As noted in https://github.com/WordPress/gutenberg/pull/57670, a couple of UI concepts in the data views work call for a SelectControl with reduced visual prominence. Two examples are; operator selection in filter configuration, and the page selector in pagination:

Screenshot 2024-07-08 at 14 03 57 Screenshot 2024-07-08 at 14 03 44

We can get halfway there by using the small size, but it would be good to have a built-in way to hide the border as well.

ciampo commented 7 months ago

It looks like that border is inherited from InputControl. Is having borderless controls a need that we should consider for the wider group of controls in the package? (cc @mirka )

Not my area of expertise, but have we considered the potential accessibility implications of a borderless dropdown, especially for visually impaired users? (cc @andrewhayward )

jameskoster commented 7 months ago

Is having borderless controls a need that we should consider for the wider group of controls in the package?

It seems unlikely there would be a need for other controls to omit the border, largely because they lose their identity with out one. A borderless SelectControl can work (in theory) because most of the time the chevron will be present and this helps indicate the purpose of the element.

Hopefully appropriate labelling, hover and focus styles can handle the accessibility requirements, but let's see what Andrew says.

ciampo commented 7 months ago

@mirka in terms of APIs, what do you think about adding a variant prop with type undefined | 'unstyled' ?

mirka commented 7 months ago

@mirka in terms of APIs, what do you think about adding a variant prop with type undefined | 'unstyled' ?

It is a possibility, but we should first assess whether the borderless style makes sense with all the available sizes/paddings, labeling options, multiple, prefix/suffix, etc. If not (which I predict will be the case here), it would be a lot simpler to make a thin facade component with a limited subset of props.

jameskoster commented 7 months ago

The use cases that have arisen essentially call for a select with a smaller footprint and less visual prominence. So the likelihood of the options you mention being required is minimal. If that points to a 'facade component' then I think it could work.

ciampo commented 7 months ago

it would be a lot simpler to make a thin facade component with a limited subset of props.

That's also a possibility. Do you think that component should live in @wordpress/components ?

mirka commented 7 months ago

Do you think that component should live in @wordpress/components ?

Yes, I think it's pretty generic. We can keep it locked while we work out the requirements.

ciampo commented 6 months ago

I think we can treat #58195 as a place to experiment with such a component's requirements, especially when striking the balance between minimal looks and accessibility.

mirka commented 1 month ago

@jameskoster I'm working on this right now, and I have some important questions about the adaptive width.

All the mockups for this borderless variant suggest that we want the select width to adapt to the width of the currently selected option.

jameskoster commented 1 month ago

This style variant is typically for cases where the select should be less visually prominent, so yes I think ideally the width of the resting state should 'hug' the chosen value. It's probably important from an a11y standpoint too... if the chevron is too far from the value then the nature of the control is less obvious.

Perhaps we start with field-sizing, and await feedback from Safari / Firefox users?

Q2: Will we always want this fit when isBorderless?

I would say so, yes.

Q3: May we sometimes want to use this fit when not borderless?

I can't think of a situation where we would right now.

ciampo commented 1 month ago

Slightly unrelated, but should we have a variant prop instead of a boolean borderless prop? That would probably give us more flexibility in the future.

mirka commented 1 month ago

Slightly unrelated, but should we have a variant prop instead of a boolean borderless prop? That would probably give us more flexibility in the future.

I was considering keeping the border a separate boolean if we're going to allow "à la carte" styling with the width hugging, but since we're going to couple the borderless styles with width styles, I think it's better to do variant like you said.