-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
WP components audit: Button Group & Toolbar #16514
Comments
Thanks for the audit. A few questions that comes to my mind based on the suggestions above:
The toggle functionality is already available in the
I guess I have the same question as above. It's possible to use an
As it exists today, it's basically just a ButtonGroup with a different API and a more opinionated design. It also supports "isCollapsed" that allows to switch between a regular toolbar and a Dropdown menu (since we need to be able to switch the way the toolbar is displayed in block toolbars depending on the context: space available, nesting...). It's not clear to me how do you propose to update these? |
Thanks for taking a look!
Partially. Is the
Yes, as long as my point about the toggle functionality is addressed above, then I think that solves the issue.
I'm suggesting that Toolbar, as it currently exists, is not appropriate for a base set of UI components, (similar to FocusPicker). The Toolbar can be generalized for UI that does not need the extra functionality that you describe. For example, this UI is in the sidebar for one of the blocks: I would classify the above UI as a ButtonGroup with IconButtons as children. I assume it's actually a Toolbar. I propose we:
|
That's up to the user basically because it just depends on how the state is setup since all of our components are "controlled" components. Exemple: (Exclusive) const ExclusiveButtonGroupUsage = () => {
const [ toggled, setToggled ] = useState( null );
const items = [ /* some array */ ];
return (
<ButtonGroup>
{ items.map( item => (
<Button
key={item.id}
isToggled={toggled === item.id}
onClick={() => setToggled( toggled === item.id ? null: item.id )}
>
{item.caption}
</Button>
</ButtonGroup>
);
} Multiple: const MultipleButtonGroupUsage = () => {
const [ toggled, setToggled ] = useState( [] );
const items = [ /* some array */ ];
const toggle = ( id ) => {
const isToggled = toggled.indexOf( if ) !== -1;
if ( isToggled ) {
setToggled( without( toggled, [ id ] ) );
} else {
setToggled( [ ...toggled, id ] );
}
}
return (
<ButtonGroup>
{ items.map( item => (
<Button
key={item.id}
isToggled={toggled.indexOf( item.id ) !== -1}
onClick={() => toggle( item.id )}
>
{item.caption}
</Button>
</ButtonGroup>
);
} What kind of API you're looking for?
I think there's something we need to clarify. It's not possible at this point to remove or rename components because we need to ensure Backward compatibility. What we can do is create new components or alias existing components (same component with two names and deprecate one of them but not remove it) |
Controlled vs Uncontrolled is something I don't know enough about. I will do some digging on that. Thank you! I believe what we want is something close to these 2 component libraries:
We should make it as easy as possible to include this functionality to lower the barrier for entry, and I believe it will create more consistent code, behavior, and functionality for everyone using these components.
This sounds like the way forward |
Props auditAs an addendum, here is a deeper evaluation of the props for these components. This is an effort to expand the components to be more useful and to answer the question, "Are properties well thought out and consistently applied?" This only covers visual props. Event handler props will be evaluated at a later date. ButtonGroupIt seems there are no props for this component. ✨ New
ToolbarNo suggestions at this point because this is a unique component for the editor and should be moved to an editor set of components. Event handler props will be evaluated at a later date. |
I'm working on making toolbars more accessible and hopefully fix #15331 But as I go, I see that In practice, it's not even used as the block toolbar as the design guidelines indicate. The block toolbar uses NavigableContainer instead and the actual toolbar code lives in the block-editor components. My initial thought was, then, to propose transforming But then I came across this: https://github.com/WordPress/gutenberg/blob/master/packages/components/src/CONTRIBUTING.md#deprecation
What would be the best way to propose/make this change? A new separate module (e.g. cc @gziolo |
Yes, totally agree that the current implementation of the
Yes, we should explore whether it's possible to refactor We would also have to introduce another component to cover what we have today in the codebase. Ideally, we should also find a way to magically make the existing code work if someone still uses Does it sound like a good approach for you? I'm happy to discuss all other alternatives. Honestly speaking, it's very challenging to ensure that old APIs continue to work while we reshape how components behave. By the way, it seems like NavigableMenu should use only arrow keys to navigate between items and tab to the next component. At the moment tabbing and arrow keys work more or less the same. At least this is what I see in the Toolbar Example at w3.org: |
@gziolo Thank you for sharing your thoughts! This approach is very reasonable, and it's nice to know that it's possible to make more drastic changes (from an API naming perspective), even if it may be challenging. A wrapper/adapter acting as the "entry point" for the +1 for deprecation messages regarding this approach 🎉 |
I'm closing out the Component Audit issues for now. |
Is your feature request related to a problem? Please describe.
This issue is part of a review on the naming, structure, and composition of the UI components as brought up in #16367
Button Group
Audit
Opportunities I came across while reviewing this component.
Grouping
Suggestions
Structure (no changes):
ButtonGroup
Note
The radio option of the ButtonGroup works similarly to TabPanel.
To clarify the difference between TabPanel and this ButtonGroup component — a tab represents a single view in a group of related views. A radio ButtonGroup represents a choice within a view. In other words, tabs are a navigational element, and ButtonGroup is not. Related: #13587
Toolbar
This component is included because of its close relation to ButtonGroup.
Audit
Opportunities I came across while reviewing this component.
Grouping
Suggestions
Alternatively, we could have 2 components:
Feedback
The feedback I'm looking for is related to naming, structure, and composition. I'm not looking for visual feedback of the components. Prop audit can be seen in the comment below.
The text was updated successfully, but these errors were encountered: