Repository navigation
Conversation
A disabled BBButton gets the native `disabled` attribute and `pointer-events: none`, so its tooltip never opens on hover and the button leaves the tab order: the reason it is disabled never reaches mouse, keyboard or screen-reader users. Consumers wrap the button and put a tooltip on the wrapper, which fixes hover only. When `disabled` and `tooltipLabel` are both set, render `aria-disabled="true"` instead of the native attribute, as BBBCheckbox and BBBToggle do: - clicks, Enter and Space are cancelled with `preventDefault()` and `onClick` is not called, so a `type="submit"` button doesn't submit its form; - the disabled look comes from `:disabled` and `[aria-disabled='true']` rather than a styling prop, so both states share it; hover and active styles apply only to an enabled button, and only a natively disabled one drops pointer events, so the tooltip opens on hover and the not-allowed cursor shows; - the stacked helper icon ignores clicks and shows no hover. The tooltip opens on `focusin` as well as hover, because in the stacked layout its reference is the wrapper, which focus never lands on. Its text is kept in a `hidden` span the button's `aria-describedby` points to, since Tippy only mounts its content while shown; this also describes stacked buttons, which Tippy's own aria-describedby never reached. A wrapper inside BBButton carrying the tooltip was discarded: a natively disabled button still can't take focus, leaving the keyboard gap. Without a tooltip, a disabled button stays natively disabled.
germanocaumo
left a comment
There was a problem hiding this comment.
Tested in Chromium, Firefox and WebKit: the button stays in the tab order in every layout, the tooltip opens on hover and focus, and clicks, Enter, Space and form submission are all blocked. The disabled look matches the native one. One fix inline, plus a small naming one.
| aria={{ content: showsTruncatedLabelTooltip ? null : 'auto' }} | ||
| // In the 'stacked' layout the reference is the wrapper, which focus never lands on; | ||
| // `focusin` bubbles up from the button, Tippy's `focus` would not. | ||
| trigger="mouseenter focusin" |
There was a problem hiding this comment.
Adding or removing tooltipLabel swaps the root between <button> and <Tippy>, so React remounts the button. With the issue's pattern (tooltipLabel only while disabled), a Start button that disables itself after Enter, or a disabled one that becomes enabled while focused, drops focus to <body>. Same fix as in #117/#118: render Tippy beside the button and point it at the root.
const buttonRef = useRef<HTMLButtonElement>(null); // ref={buttonRef} on both Styled.Button roots
const wrapperRef = useRef<HTMLDivElement>(null); // ref={wrapperRef} on Styled.ButtonWrapper
// …
return (
<>
{buttonElement}
{(tooltipLabel || showsTruncatedLabelTooltip) && (
<Tippy
reference={layout === LAYOUTS.STACKED ? wrapperRef : buttonRef}
content={tooltipLabel || label}
/* …same props as now */
/>
)}
</>
);Focus stays put in all three browsers, and nothing else in my checks changes.
| accessibilityProps['aria-labelledby'] = defaultLabelId; | ||
| } | ||
| if (ariaDescribedBy) accessibilityProps['aria-describedby'] = ariaDescribedBy; | ||
| const describedBy = [ariaDescribedBy, tooltipLabel && tooltipDescriptionId].filter(Boolean).join(' '); |
There was a problem hiding this comment.
An icon-only button with only a tooltipLabel (no label or ariaLabel) ends up with no name and the tooltip as its description. Same rule as BBBCheckbox/BBBToggle: when nothing else names it, point aria-labelledby at the tooltip span instead.
What does this PR do?
A disabled BBButton gets the native
disabledattribute andpointer-events: none, so its tooltip never opens on hover and the button leaves the tab order: the reason it is disabled never reaches mouse, keyboard or screen-reader users. Consumers wrap the button and put a tooltip on the wrapper, which fixes hover only.When
disabledandtooltipLabelare both set, renderaria-disabled="true"instead of the native attribute, as BBBCheckbox and BBBToggle do:preventDefault()andonClickis not called, so atype="submit"button doesn't submit its form;:disabledand[aria-disabled='true']rather than a styling prop, so both states share it; hover and active styles apply only to an enabled button, and only a natively disabled one drops pointer events, so the tooltip opens on hover and the not-allowed cursor shows;The tooltip opens on
focusinas well as hover, because in the stacked layout its reference is the wrapper, which focus never lands on. Its text is kept in ahiddenspan the button'saria-describedbypoints to, since Tippy only mounts its content while shown; this also describes stacked buttons, which Tippy's own aria-describedby never reached.A wrapper inside BBButton carrying the tooltip was discarded: a natively disabled button still can't take focus, leaving the keyboard gap. Without a tooltip, a disabled button stays natively disabled.
Closes Issue(s)
Closes #125