Describe a Button with a Tooltip
Write the code, see it run, pass the checks.
The problem
- easy
- Code
An icon-only Save button needs a tooltip. Render a button named "Save" (aria-label="Save", showing a πΎ icon), followed by a "Publish" button. While the pointer is over the Save button, or the Save button has keyboard focus, show a tooltip: an element with role="tooltip", an id, and the text "Saves your draft". The rest of the time, leave it out or hide it with the hidden attribute. While the tooltip shows, the Save button's aria-describedby holds the tooltip's id, so screen readers read the tip after the button's name. Pressing Escape hides the tooltip without moving focus.
Your code must pass
- No tooltip shows at first
- Hovering the button shows the tooltip, and leaving hides it
- Focusing the button shows the tooltip, and moving focus away hides it
- The button is described by the tooltip
- Escape hides the tooltip and keeps focus on the button