mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.95k stars 32.27k forks source link

[Checkbox] Add checked animation #12639

Open SamiSaves opened 6 years ago

SamiSaves commented 6 years ago

The Checkbox component is missing the animation for the icon when toggling it. This makes checking the checkbox look bit cluncky, especially when toggling it from the label.

In material design demo you can clearly see the icon animated when you toggle it: https://material-components.github.io/material-components-web-catalog/#/component/checkbox

Compare it to the current implementation in material-ui. See especially how it looks when toggling it by clicking the label. https://material-ui.com/components/checkboxes/

Even in v0 has some kind of animation, which in my opinion makes it look better than the current version https://v0.material-ui.com/#/components/checkbox

Edit: Updated outdated link

eps1lon commented 6 years ago

Good catch. The design spec also displays an animation: https://material.io/design/components/selection-controls.html#checkboxes

It currently has a transition but for fill whereas mcw has an opacity transition. That might be the issue here?

calebissharp commented 6 years ago

@eps1lon Is it alright if I work on this?

eps1lon commented 6 years ago

@calebissharp That'd be great.

oliviertassinari commented 5 years ago

In case somebody wants to work on this issue, he can benchmark MCW implementation.

Oct-31-2019 18-13-59

NawarA commented 4 years ago

Also, opening this open to a greater discussion, the spec calls for animated icons, with 3 durations: simple (100 ms - what MUI currently uses), (200ms average - the checkbox example above), and complex (500ms).

spec: https://material.io/design/iconography/animated-icons.html#usage

Looks like there are a few transitions here: 1) enable to disable (and the reverse transition) 2) transition between two icons on click 3) animate the same icon onclick

eluchsinger commented 4 years ago

@oliviertassinari Did anyone work on this one? Would it still be in v4 or already v5?

oliviertassinari commented 4 years ago

@eluchsinger Not I'm aware of. I would be cautious with the bundle size and customization implications. I don't think that it should land in v4.

paperdave commented 4 years ago

much earlier when i animated the radio button component, i also started working on this issue, but never finished it. a partial implementation of the animated checkbox is on npm but it's not complete, nor the most quality code.

for people who are browsing this issue and just want a thing that works, that may be of use to them.

eluchsinger commented 4 years ago

I would do it myself, but I am not an animations expert and lack a bit of the time to look into it. If I find some time I can do it myself and create a PR.

benatkin commented 4 years ago

Notably GMail doesn't use it, at least for selecting messages. It would be interesting design decision to default to animated in long forms but default to Material UI's current implementation in table views. Not one I'm capable of making except for my own sites because IANAD but it seems like a good idea to me! I'm also sure Material UI could handle it but not sure it would be worth the effort.

NawarA commented 4 years ago

re: worth the effort.

Its just CSS animations, right? lol Can't we use Google's open source repo for CSS? The code is right there ;)

I believe all great UI's feel good. Anything that can make the library feel better is a worthwhile investment for everyone in the community. You're totally right, that developers should be able to choose which animation to use. According to the Material spec, developers / designers should be using animations that are simple, average, and complex, which supports your insight.

Below is a screenshot / video from the spec, found here.

MUI currently supports simple. This feature request is to support average, just like Google shows off in their MUI web components. I totally agree, developers / designers need to have final say on where to utilize each.

🖖

Video link: Screenshot

benatkin commented 4 years ago

As for effort, I was specifically talking about the effort to have different defaults for table row checkboxes, for which animations could get in the way, and form checkboxes, which would be welcome, especially in sign up forms! And I realize it could be easy to have a partial solution for differing defaults, but it would need to be built to the standards of Material UI, and it may be better just to default to animated or to not animated.

benatkin commented 4 years ago

"developers / designers need to have final say of which to utilize, and where."

Well said!

VityaSchel commented 3 years ago

In case somebody wants to work on this issue, he can benchmark MCW implementation.

Oct-31-2019 18-13-59

I ended up using official material components module. Below is my MaterialCheckbox component which supports color prop and onChange event but I encourage everyone who wants to implement checkbox animation to write their own component.

Code + demo `npm install @material/checkbox` ```javascript import '@material/checkbox/dist/mdc.checkbox.css' MaterialCheckbox.propTypes = { id: PropTypes.number.isRequired, children: PropTypes.node, color: PropTypes.string, onChange: PropTypes.func, checked: PropTypes.bool, disabled: PropTypes.bool } function MaterialCheckbox(props) { return (
{})} checked={props.checked} disabled={props.disabled} />
) } ``` Usage: ```javascript const [checked, setChecked] = React.useState(false) setChecked(e.target.checked)} checked={checked}>Foo bar ``` https://user-images.githubusercontent.com/59040542/122215318-22ec0a00-cebc-11eb-9421-ae82507e770a.mp4
TamirCode commented 2 years ago

is there an official way to add this to my MUI checkbox yet? even a simple opacity transition would be better than nothing

Slowl commented 1 year ago

Bumping this issue for 2023.

We could indeed handle this ourselves but having a default animation should be the minimum in my opinion when we disable the ripple effect. Many popular libraries have an animation like Mantine or Chakra for example

yuvalkarmi commented 9 months ago

Edit 2: For anyone just looking for a solution that still uses native MUI components in the meantime, I created this component called CheckboxWithLabelAndRipple, here's the code: https://gist.github.com/yuvalkarmi/215451742b09bcb25498deffe3ebfa9b


Edit 1: I just realized after reading @Slowl's comment more carefully that there already is an animation on the original Checkbox component... sort of. There's a ripple effect, but only if you click directly on the checkbox itself -- not on the label.

If you use the Checkbox in a FormControlLabel (e.g. from the docs <FormControlLabel control={<Checkbox defaultChecked />} label="Label" />), then there is no ripple animation when the click is on the label, and therefore no animation at all, which is out of sync with the material design spec.


Original comment:

Bumping this issue for 2024 :)

This implementation is fantastic: https://codepen.io/abottega/pen/vNzQMo

Would love to see this make it in MUI <3