CommandBar: Tooltip for icon-only buttons
Feature request
So far we've been using aria-label plus title in buttons that only display icon in the CommandBar. For this sake, name property was emptied.
However, title doesn't look nice and it doesn't behave well with screen reader. So we want to use a TooltipHost instead around the buttons which IContextualMenuItem provides a brand new tooltip property.
So proposal is:
- Add optional
tooltipproperty to IContextualMenuItem. As per discussion on #1777, this won't ever be used in ContextualMenu, only in CommandBar. - Render a TooltipHost around the rendered button/link for items with
tooltipprop. - If
tooltipis provided, use it as fallback value foraria-label, only if this ornameare not provided.
I'm ready to submit a PR with this change.
I think this could also be acheived by just providing an onRender function in your IContextualMenuItem, although adding a tooltip prop could work. The negative I would suggest here is that many of these components now have the aria-label prop which is sort of standard and an onRender prop which is sort of standard. If we think it's valuable to allow users to add tooltips to components, and it's valuable for us to render those tooltips for them as opposed to just exposing the onRender, we should look to do it for all components, in order to be consistent.
I think having both tooltip and aria-label prop could certainly work, and I like that it is explicit in their differences in terms of what we use the prop for, we could also be smart about it and setAriaDescribedBy="false" on the tooltip if tooltip === aria-label.
Is there any reason why an onRender function doesn't meet your needs here? that seems like the easiest thing to do
I'm in the process of rewriting the command bar using the new overflow set and resize group. This should simplify the component greatly and give you some more flexibility.
Here's the current component. I still have some styling work to do, but the functionality is mostly there. I'll probably add the ability to override the button rendering if you need to do something custom in there.
https://github.com/micahgodbolt/office-ui-fabric-react/blob/command-bar-refactor/packages/office-ui-fabric-react/src/components/CommandBar/CommandBar.tsx
@petdun2519 Overriding onRender would require consumer to duplicate a lot of rendering logic (all these lines), which would be prone to become stale as library evolves.
I see onRender useful for edge cases, but tooltip seems a pretty standard feature to follow that path.
Btw I love this part:
we could also be smart about it and setAriaDescribedBy="false" on the tooltip if tooltip === aria-label It would require changes in TooltipHost, but I can do them as part of this issue.
@micahgodbolt Your refactoring looks awesome! If you respect current IContextualMenuItem contract, you will have to take care of onRender, but as I said I don't want to duplicate the library rendering code outside just to add a tooltip (even when that code is much less now). IContextualMenuItem is such an great abstraction that it will allow migrating to the new implementation painless. On the other hand, onRender is an abstraction bypass that won't migrate so smoothly and may cause other issues as the component evolves in the future.
Summing up, IMO tooltip is a standard attribute for any command and many other consumers of Fabric will take advantage of it easily. But if you guys feel strong against it being part of IContextualMenuItem, I won't submit any PR and will work around it on my own code.
Got this working in the new commandBar :)
Will close this issue once it's merged in.
