Skip to content

feat(BBButton): add labelOverflow prop - #120

Open
Arthurk12 wants to merge 3 commits into
bigbluebutton:developfrom
Arthurk12:issue/106
Open

Arthurk12 wants to merge 3 commits into
bigbluebutton:developfrom
Arthurk12:issue/106

Conversation

@Arthurk12

Copy link
Copy Markdown
Member

What does this PR do?

Adds a labelOverflow prop to BBButton's default layout. It sets what happens when the label doesn't fit the button's available width.

  • labelOverflow="nowrap" (default): keeps today's behavior. The label stays on one line, and the button grows or the label overflows. Existing buttons don't change.
  • labelOverflow="wrap": the label breaks onto more lines, making the button taller.
  • labelOverflow="ellipsis": the label is truncated with an ellipsis, and the button can shrink as a flex item. While the label is truncated and no tooltipLabel is set, the full label shows in a tooltip.
  • Storybook: a new Default story renders a single button driven by the controls, so the Docs page's top preview now responds to them. A new Label Overflow story compares the three values.
  • README: new "Long Labels" section and Props table row.

Closes Issue(s)

Closes #105
Closes #106

Motivation

In a narrow container or a row of equal-width buttons, such as the BigBlueButton 4.0 breakout rooms panel, a long or translated label overflows the button or pushes the row wider. Consumers work around this today by overriding styles on BBButton's internal markup.

BBButton's default layout always keeps its label on one line
(`white-space: nowrap`). When the button can't grow, for example a
`fullWidth` button in a narrow popover or a row of equal-width buttons,
a long label overflows the button or pushes the row wider. Consumers
work around it by reaching into BBButton's markup: `white-space:
normal` overrides to let the label wrap, or rules on the internal label
<span> to truncate it with an ellipsis, which is not part of the public
API.

Add a `labelOverflow` prop to the default layout, setting what happens
when the label doesn't fit the button's available width:

- `nowrap` (default) keeps today's behavior, so no existing button
  changes.
- `wrap` sets `white-space: normal` and `overflow-wrap: break-word`,
  so the label breaks onto more lines and a single word too long for
  the button breaks instead of overflowing.
- `ellipsis` gives the button `min-width: 0` and `max-width: 100%`, so
  it can shrink as a flex item and stay within its container, and
  truncates the label with an ellipsis.

Truncation hides part of the label from sighted users, and most such
buttons have no `tooltipLabel`. While the label is actually truncated,
detected with a ResizeObserver comparing scrollWidth and clientWidth,
and no `tooltipLabel` is set, the full label shows as a tooltip on
hover and focus. A single Tippy is kept mounted and toggled through
`disabled`, so the button is not remounted (losing focus) when the
truncation state changes. That tooltip sets `aria.content` to null,
because the label is already the accessible name via aria-labelledby
and would otherwise be announced again as a description.

Separate `wrapLabel` and `truncateLabel` booleans were considered and
discarded: they can be combined into a contradictory state, and a name
describing the action doesn't say it only applies when the label
doesn't fit. Wrapping by default was also considered; it would make
buttons that overflow today taller, so it is left out of this change.
The first story in a file is the one Storybook shows in the Docs page's
top preview and binds to its Controls table. For BBButton that story
is Primary, which renders three buttons with fixed labels, one per
color. The preview shows three buttons instead of one, and the fixed
labels override the `label` control, so editing it has no visible
effect.

Add a Default story, rendering a single button from the story args,
as the first export. Every other component in the library already
starts with a Default story. Primary and the other variant stories
keep their fixed labels, since they exist to compare colors and sizes
side by side.

@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 base vs head in Chromium, Firefox and WebKit. ellipsis works in a flex row, a block container and with fullWidth. The tooltip shows only while the label is truncated, and the button keeps focus as that changes. Two one-line fixes inline.

#119 changes the same <Tippy>. Whichever PR merges second should keep plugins={TOOLTIP_PLUGINS} there, so the truncated-label tooltip also closes with Escape.

Comment thread src/components/Button/styles.ts Resolved
Comment thread src/components/Button/component.tsx Resolved
feat(BBButton): add labelOverflow prop

BBButton's default layout always keeps its label on one line
(`white-space: nowrap`). When the button can't grow, for example a
`fullWidth` button in a narrow popover or a row of equal-width buttons,
a long label overflows the button or pushes the row wider. Consumers
work around it by reaching into BBButton's markup: `white-space:
normal` overrides to let the label wrap, or rules on the internal label
<span> to truncate it with an ellipsis, which is not part of the public
API.

Add a `labelOverflow` prop to the default layout, setting what happens
when the label doesn't fit the button's available width:

- `nowrap` (default) keeps today's behavior, so no existing button
  changes.
- `wrap` sets `white-space: normal` and `overflow-wrap: anywhere`, so
  the label breaks onto more lines and a single word too long for the
  button breaks instead of overflowing. `break-word` is not enough: it
  doesn't lower the button's min-content width, so a long word still
  widens the button past its container.
- `ellipsis` gives the button `min-width: 0` and `max-width: 100%`, so
  it can shrink as a flex item and stay within its container, and
  truncates the label with an ellipsis.

Truncation hides part of the label from sighted users, and most such
buttons have no `tooltipLabel`. While the label is actually truncated,
detected with a ResizeObserver comparing scrollWidth and clientWidth,
and no `tooltipLabel` is set, the full label shows as a tooltip on
hover and focus. A single Tippy is kept mounted and toggled through
`disabled`, so the button is not remounted (losing focus) when the
truncation state changes. That tooltip sets `aria.content` to null,
because the label is already the accessible name via aria-labelledby
and would otherwise be announced again as a description. `aria` is
passed on every render, since Tippy keeps the previous value when the
prop is omitted.

Separate `wrapLabel` and `truncateLabel` booleans were considered and
discarded: they can be combined into a contradictory state, and a name
describing the action doesn't say it only applies when the label
doesn't fit. Wrapping by default was also considered; it would make
buttons that overflow today taller, so it is left out of this change.

@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.

verified and working

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