-
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
Button: Support "unstyled" usage #67320
Comments
A useful exercise could be to run through Also, we may want to "merge" the |
I’d like to implement this enhancement but wanted to discuss the approach first. To keep the code DRY, I propose extracting base button styles into reusable mixins (focus, active, disabled, etc.) and applying them under The For example: gutenberg/packages/components/src/button/style.scss Lines 41 to 46 in 8783607
Extracting the above styles into a mixin ( What do you think of this approach? I’d appreciate any guidance or suggestions for improvement. |
Hey @yogeshbhutkar, thank you for the comment! I'm not exactly sure what @mirka had in mind when proposing a Probably better to wait for @mirka 's feedback before moving forward, also considering that an alternative to the approach was to provide an |
Thanks for the reply, @ciampo.
The issue with an unstyled variant is that a developer may only need to override layout styles like height while keeping the existing focus, hover, and other interactive styles. Exposing these styles via a hook allows them to be easily retrieved and applied as class names. Otherwise, important accessibility considerations might need to be made consciously. I’m thinking const { ...defaults } = useButtonStyles();
// To apply only the focus styles.
const { focusStyle } = useButtonStyles(); Essentially, Edit: |
Thank you for thinking about this, @yogeshbhutkar! I just thought of yet another approach, which is kind of the opposite: subtractive styles, instead of additive composition. So instead of composing together the styles that you want, you disable the styles that you don't want. <Button data-styles-no-focus /> // packages/components/src/button/style.scss
// Use a `:where()` so we don't alter the specificity any further
&:focus:not(:disabled):where(:not([data-styles-no-focus])) {
/* focus styles */
} I wonder if this might be more ergonomic and intuitive for consumers. Anyway though, I want to reemphasize the first part of my proposed plan, which is to audit the repo for the types of legitimate style overrides we have. This will inform whether it makes more sense to provide an additive or subtractive way to customize styles. |
What problem does this address?
There have been cases where the
Button
component is used with heavy style overrides. This can lead to subtle bugs and breakages down the line.Although we should always first reconsider if one of the standard Button style variants can be used instead, in some cases heavy style customization is warranted. While styling a simple
button
element from scratch may seem like a valid alternative, that may also lead to developers overlooking subtle considerations (focus styles, accessibility, etc) that are already handled inButton
.What is your proposed solution?
We should audit the repo for the kinds of valid style overrides we have, and figure out how Button can support those use cases cleanly. Some possibilities include:
unstyled
variantuseButtonStyles
hookThe text was updated successfully, but these errors were encountered: