Skip to content

Commit 0b6001a

Browse files
authored
fix: ButtonGroup overflow detection for labels without word break (adobe#10186)
* fix: buttongroup resizes when labels have no breaks * add test * fix in v3
1 parent 832519e commit 0b6001a

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

packages/@adobe/spectrum-css-temp/components/buttongroup/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ governing permissions and limitations under the License.
1919
align-items: flex-start;
2020
/* necessary so that offsetLeft on button children is correct */
2121
position: relative;
22+
max-width: 100%;
2223

2324
.spectrum-ButtonGroup-Button {
2425
flex-shrink: 0;

packages/@react-spectrum/s2/src/ButtonGroup.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const buttongroup = style<ButtonGroupStyleProps>(
6565
{
6666
display: 'inline-flex',
6767
position: 'relative',
68+
maxWidth: 'full',
6869
gap: {
6970
size: {
7071
S: 8,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2026 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {Button} from '../src/Button';
14+
import {ButtonGroup} from '../src/ButtonGroup';
15+
import {describe, expect, it} from 'vitest';
16+
import React from 'react';
17+
import {render} from './utils/render';
18+
19+
describe('ButtonGroup', () => {
20+
it('stacks vertically when the container shrinks below the width of buttons with no-space labels', async () => {
21+
let {container} = await render(
22+
<div style={{width: '500px'}} data-testid="wrapper">
23+
<ButtonGroup data-testid="button-group">
24+
<Button variant="primary">nospace</Button>
25+
<Button variant="secondary">nospace</Button>
26+
<Button variant="secondary">nospace</Button>
27+
</ButtonGroup>
28+
</div>
29+
);
30+
31+
let wrapper = container.querySelector('[data-testid="wrapper"]') as HTMLElement;
32+
let buttonGroup = container.querySelector('[data-testid="button-group"]') as HTMLElement;
33+
34+
// Initially wide — buttons should be laid out horizontally
35+
expect(getComputedStyle(buttonGroup).flexDirection).toBe('row');
36+
37+
// Shrink the container below the combined button widths to trigger overflow detection
38+
wrapper.style.width = '50px';
39+
40+
// Wait for ResizeObserver and React re-render to settle
41+
await expect.poll(() => getComputedStyle(buttonGroup).flexDirection).toBe('column');
42+
43+
// Restore the container width — should return to horizontal
44+
wrapper.style.width = '500px';
45+
await expect.poll(() => getComputedStyle(buttonGroup).flexDirection).toBe('row');
46+
});
47+
});

0 commit comments

Comments
 (0)