Skip to content

feat: add BBButton pressed state, BBBButtonGroup and BBBSegmentedControl - #127

Open
Arthurk12 wants to merge 3 commits into
bigbluebutton:mainfrom
Arthurk12:issue/107
Open

Arthurk12 wants to merge 3 commits into
bigbluebutton:mainfrom
Arthurk12:issue/107

Conversation

@Arthurk12

Copy link
Copy Markdown
Member

What does this PR do?

Adds a pressed (selected) state to BBButton, plus two components built on it: a layout group for side panel buttons and a single-choice option group.

  • BBButton pressed prop: true/false renders aria-pressed; true applies a selected fill per color that holds through hover and press. A disabled pressed button fades its fill instead of turning grey, so the current choice stays visible.
    02a-button-pressed-toggle-off02b-button-pressed-toggle-on 01-button-pressed

  • New BBBButtonGroup: lays buttons out in one row of equal-width buttons and stacks them at full width according to stack: never (default), always, width (below stackBelow, default 20.75rem) or overflow (once the widest label no longer fits its share of the row).
    05-buttongroup-stack-on-overflow06-buttongroup-always-stacked03-buttongroup-default

  • BBBButtonGroup footer prop: renders a divider above the buttons for side panel footers and makes stack="width" the default.
    04-buttongroup-footer

  • New BBBSegmentedControl: a controlled group where exactly one option is selected, rendered as pressed buttons under role="group"; clicking the selected option does not call onChange. Accepts stack/stackBelow, passed to BBBButtonGroup.

    08-segmentedcontrol-stacked 10-segmentedcontrol-disabled-option
    07-segmentedcontrol-default 09-segmentedcontrol-disabled

  • READMEs, Storybook stories and demo images for all three; both components are exported per entry point (/ButtonGroup, /SegmentedControl).

Closes Issue(s)

Closes #107

Motivation

Toggle buttons, single-choice groups and the two-buttons-then-stack panel footer are rebuilt by hand in each BigBlueButton client panel, with style overrides for the selected state and no selection announced to screen readers.

More

  1. Run npm run storybook.
  2. BBButton › Pressed: each color shows a pressed fill that stays on hover; the disabled pair keeps a faded fill.
  3. BBBButtonGroup › Footer: the wide panel shows a divider and two buttons side by side; the narrow one stacks them. Drag a panel's corner across ~22.75rem to see it switch.
  4. BBBButtonGroup › Stack on Overflow: only the panel with the long label stacks.
  5. BBBSegmentedControl › Default: clicking Stopwatch moves the selection; the Disabled story keeps the selected option visible.
  • The pressed colors and the disabled opacity still need design approval.
  • Added/updated documentation

BBButton has no selected state, so a toggle button, or a group where
one option is picked, has to be painted by the consumer. The poll
panel's response-type picker switches variants and repaints both states
with eight !important declarations, because the library's hover rule
outranks any ordinary override, and screen readers hear plain buttons
with no selection.

Add a `pressed` prop. When it is set, the button renders `aria-pressed`;
when it is true, the button gets a fill that holds through hover and
active. The fill depends on `color` only, so a pressed button reads as
selected next to any variant, and the colors live in a table in
constants.ts for the design team to refine. A pressed button that is
also disabled fades its fill instead of turning grey, so a disabled
group still shows which option is selected.

Forwarding `aria-pressed` alone was considered: it fixes the
accessibility gap but leaves the style overrides in place.

Closes bigbluebutton#107
Side panels in the BigBlueButton client lay out their footer buttons by
hand: two buttons side by side that stack once the panel gets too
narrow, under a divider. Each panel redeclares its own divider, gaps
and wrapping rules.

Add BBBButtonGroup, which lays its children out in one row of
equal-width buttons and stacks them at full width according to
`stack`: never, always, once the group is narrower than `stackBelow`,
or once the widest button no longer fits its share of the row, measured
with a ResizeObserver. `footer` renders a BBBDivider above the buttons
and makes the width rule the default. Where the group sits in the panel
stays up to the panel.

The width rule uses flex-basis arithmetic instead of a container query,
because styled-components 5, which the client uses, drops the selector
of a nested @container rule. A plain wrapping flex-basis was discarded
because with three or more buttons it splits them across uneven rows;
the group stacks all or nothing.
Groups where exactly one option is picked are built by hand in the
BigBlueButton client: the timer panel's Timer/Stopwatch switch, the
poll response types and the poll/quiz selector. The timer disables the
selected button so it cannot be clicked again, which screen readers
announce as unavailable rather than selected.

Add BBBSegmentedControl, a controlled group that renders each option as
a BBButton and marks the selected one with `pressed`, under
role="group". Clicking the selected option does not call `onChange`, so
consumers no longer need to disable it, and disabling the whole group
keeps the selected option visible. The options are laid out by
BBBButtonGroup, and `stack` and `stackBelow` are passed through to it.

Radiogroup semantics with arrow-key navigation were discarded for now:
they need BBButton to forward refs and accept role, aria-checked and
tabIndex. The group can switch to them later without changing its API.
Tabs are left out because these groups pick a value rather than
switch between views.
Comment on lines +55 to +58
const observer = new ResizeObserver(check);
observer.observe(buttons);
return () => observer.disconnect();
}, [stack, children]);

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.

children is new on every parent render, so with stack="overflow" this forces a layout and creates a new ResizeObserver each time (20 renders, 20 observers). Depending on [stack] and catching label changes with a MutationObserver keeps the behaviour:

Suggested change
const observer = new ResizeObserver(check);
observer.observe(buttons);
return () => observer.disconnect();
}, [stack, children]);
const resizeObserver = new ResizeObserver(check);
resizeObserver.observe(buttons);
const mutationObserver = new MutationObserver(check);
mutationObserver.observe(buttons, { subtree: true, childList: true, characterData: true });
return () => {
resizeObserver.disconnect();
mutationObserver.disconnect();
};
}, [stack]);

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.

BBButton: pressed state for toggle buttons

2 participants