Skip to content

fix(BBButton): keep a disabled button with a tooltip focusable - #126

Open
Arthurk12 wants to merge 1 commit into
bigbluebutton:developfrom
Arthurk12:issue/125
Open

Arthurk12 wants to merge 1 commit into
bigbluebutton:developfrom
Arthurk12:issue/125

Conversation

@Arthurk12

Copy link
Copy Markdown
Member

What does this PR do?

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.

Closes Issue(s)

Closes #125

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 germanocaumo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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(' ');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants