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

[SpeedDial] Rework part of the logic #17301

Merged
merged 6 commits into from
Sep 15, 2019

Conversation

hashwin
Copy link
Contributor

@hashwin hashwin commented Sep 3, 2019

Reimplementing #12870 with the updated material-ui.
This updates persistent tooltip styles to match the material design guide (https://material.io/components/buttons-floating-action-button/#types-of-transitions).

Speed_Dial_React_component_-_Material-UI

For people updating their code from @material-ui/lab@4.0.0-alpha.26 to alpha.27, the following diff should be enough:

      <SpeedDial
        ariaLabel="SpeedDial tooltip example"
        className={classes.speedDial}
        hidden={hidden}
        icon={<SpeedDialIcon />}
-       onBlur={handleClose}
-       onClick={handleClick}
+       onClose={handleClose}
-       onFocus={handleOpen}
-       onMouseEnter={handleOpen}
-       onMouseLeave={handleClose}
+       onOpen={handleOpen}
        open={open}
      >

@mui-pr-bot
Copy link

mui-pr-bot commented Sep 3, 2019

@material-ui/lab: parsed: +0.78% , gzip: +0.34%

Details of bundle changes.

Comparing: 0ddd56f...81a92f8

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core +0.03% 🔺 +0.05% 🔺 331,664 331,756 90,529 90,570
@material-ui/core/Paper +0.02% 🔺 +0.04% 🔺 68,644 68,659 20,449 20,458
@material-ui/core/Paper.esm +0.02% 🔺 +0.06% 🔺 62,083 62,098 19,192 19,203
@material-ui/core/Popper 0.00% 0.00% 28,397 28,397 10,159 10,159
@material-ui/core/Textarea 0.00% 0.00% 5,082 5,082 2,132 2,132
@material-ui/core/TrapFocus 0.00% 0.00% 3,766 3,766 1,596 1,596
@material-ui/core/styles/createMuiTheme +0.09% 🔺 +0.17% 🔺 16,333 16,348 5,808 5,818
@material-ui/core/useMediaQuery 0.00% 0.00% 2,488 2,488 1,050 1,050
@material-ui/lab +0.78% 🔺 +0.34% 🔺 153,589 154,786 46,739 46,896
@material-ui/styles 0.00% 0.00% 51,420 51,420 15,288 15,288
@material-ui/system 0.00% 0.00% 15,581 15,581 4,351 4,351
Button +0.02% 🔺 +0.04% 🔺 78,595 78,610 24,014 24,024
Modal +0.10% 🔺 +0.24% 🔺 14,527 14,542 5,102 5,114
Portal 0.00% 0.00% 2,907 2,907 1,318 1,318
Rating +0.02% 🔺 +0.05% 🔺 69,948 69,963 21,844 21,856
Slider +0.02% 🔺 +0.05% 🔺 75,069 75,084 23,173 23,184
colorManipulator 0.00% 0.00% 3,835 3,835 1,519 1,519
docs.landing 0.00% 0.00% 52,232 52,232 13,768 13,768
docs.main +0.01% 🔺 +0.03% 🔺 597,147 597,233 190,633 190,685
packages/material-ui/build/umd/material-ui.production.min.js +0.02% 🔺 +0.05% 🔺 302,599 302,665 86,944 86,984

Generated by 🚫 dangerJS against 81a92f8

@oliviertassinari oliviertassinari added the component: speed dial This is the name of the generic UI component, not the React module! label Sep 3, 2019
@oliviertassinari oliviertassinari changed the title Fix persistent tooltip labels [SpeedDial] Fix persistent tooltip labels Sep 9, 2019
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort.

@oliviertassinari oliviertassinari added the design: material This is about Material Design, please involve a visual or UX designer in the process label Sep 9, 2019
@oliviertassinari oliviertassinari self-assigned this Sep 9, 2019
@oliviertassinari oliviertassinari changed the title [SpeedDial] Fix persistent tooltip labels [SpeedDial] Rework part of the logic Sep 10, 2019
@oliviertassinari oliviertassinari force-pushed the hashwin/persistent_tooltip branch 2 times, most recently from 59b8e6d to c8c5e62 Compare September 10, 2019 02:17
@oliviertassinari oliviertassinari removed their assignment Sep 10, 2019
@oliviertassinari oliviertassinari force-pushed the hashwin/persistent_tooltip branch 5 times, most recently from 2523221 to ee1e6a0 Compare September 10, 2019 11:18
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, it should be ready for review. I have done a few aggressive changes, I hope it's fine.

@mbrookes
Copy link
Member

A couple of observations from playing with it (with no reference to the code):

When you tab onto the Fab the speed-dial opens, and you can then use the cursor keys to navigate the items. If the SpeeDial is closed (escape or space keys) key or by triggering an item (enter or space keys on an item), the cursor keys still navigate the items, but with incorrect focus appearance:

image

(sorry about the big image, retina macbook scaling issue)

In the case of preessing escape when an item is focussed, focus doesn't return to the Fab, and the behaviour is as above.

Also, when the speed-dial is horizontal, should the up-down arrow keys still work? (How does a blind keyboard user know the orientation of a pop-up?)

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 10, 2019

@mbrookes Thanks for the functionnal review, I have tried to solve all the concerns. However, I have no idea how to solve the incorrect tooltip focus display.

@mbrookes
Copy link
Member

I have no idea how to solve the incorrect tooltip focus display.

Let's leave it for now then. That's still a huge number of issues resolved. Nice work guys!

open={open}
>
{actions.map(action => (
<SpeedDialAction
key={action.name}
icon={action.icon}
tooltipTitle={action.name}
onClick={handleClick}
onClick={handleClose}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be more helpful to have a click handler that shows how to identify which action has been clicked, before it calls onClose?

Copy link
Member

@oliviertassinari oliviertassinari Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could help, it would make the demo a bit more verbose, but could teach people a valuable pattern.

Copy link
Member

@mbrookes mbrookes Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From (past) personal experience, it's the kind of thing React beginners struggle with. I think it might be worth a little verbosity.

Copy link
Member

@oliviertassinari oliviertassinari Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that people can leverage index based handler when displaying data from the server, for instance, in the case of inbox (R.I.P.), the most frequent contacts. Or in the case of Google Calendar, I would expect each action to have a named custom handler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to action this comment. I would expect most people to have a fixed set of options (not using an array). However, our demo is using an array for the sake of minimizing the demo length. I believe these two objectives contradict themselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the point is that the click handler does not handle each action differently which should be the most common use case. Otherwise why have a speed dial if every action does the same (which only closes at the moment). I would expect that you want to dispatch some action. It would be nice if this demo would handle that case.

At least this is how I understood @mbrookes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, this sounds good 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eps1lon Yeah, that's the crux of it. I took it from @oliviertassinari's comment that in real usage you wouldn't use a mapped array, but would compose each action component. If each then calls a different click handler, the issue goes away.

I had pictured a common handler that dispatches a different event according to the calling action.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use an inline handler that captures the action. A mapped array is the first iteration you would do. The rest is premature optimization.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge, I think that we can apply the handler changes in another pull request :).

@oliviertassinari oliviertassinari merged commit e9f26fc into mui:master Sep 15, 2019
@dankolesnikov
Copy link

Thank you for your work, everyone! SpeedDial is very helpful to us.

@lsnch
Copy link
Contributor

lsnch commented Oct 1, 2019

Is there now a way to disable open/close on hover?

@oliviertassinari
Copy link
Member

@lsnch Right now, you can use the first event argument and look at event.type. You can ignore mouse enter events.

@lsnch
Copy link
Contributor

lsnch commented Oct 1, 2019

It seems there's something async going on, maybe the callback gets delayed for the sake of animation.
Here it says I'm trying to access synthetic event too late.
https://codesandbox.io/s/material-demo-5dptv

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 1, 2019

@lsnch Oh, thanks for reporting it. Yes, there is an async logic to debounce events. In this case, I would propose the following:

  1. We add an event.persist() call, in case somebody wants to play with the event, we already do it for the Tooltip. I think that point is safe to move forward. ✅
  2. We add a reason second argument to the onOpen / onClose callbacks, it's a pattern we already use in the case base. Possible values could be: escapeKeyDown, focus, blur, toggle, mouseEnter, and mouseLeave? 🤷‍♂️

A proposal to double-check with @mbrookes. If we agree, would you be intersted in submitting a pull request? :)

@mbrookes
Copy link
Member

mbrookes commented Oct 1, 2019

Sounds good.

@lsnch
Copy link
Contributor

lsnch commented Oct 1, 2019

Yeah, absolutely, I'll give it a go.

@oliviertassinari
Copy link
Member

@lsnch Will you have some time in the next few days? :)

@lsnch
Copy link
Contributor

lsnch commented Oct 8, 2019

Yeah, sorry I took so long, didn't realize it was such a minor change.

@acroyear
Copy link
Contributor

Thanks for all of this work. I'd stopped using SpeedDial a while ago due to it not working right on touch-screen desktops. Gave it a try today and it is working wonderfully.

@oliviertassinari
Copy link
Member

@acroyear We are happy to hear it :D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment