Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): a labelled Button keeps its name in macOS 14 WebKit (#10256)

Cindy Zhangc48bb2334c49
diff --git a/.changeset/button-label-name-webkit.md b/.changeset/button-label-name-webkit.md
new file mode 100644
index 0000000000..679e76019b
--- /dev/null
+++ b/.changeset/button-label-name-webkit.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A labelled `Button` has its accessible name again in VoiceOver on macOS 14 (Safari 17 and WKWebView). The label sat inside a `display: contents` wrapper, which that WebKit drops names through, so it read an unnamed "button". The wrapper is now a flex box that takes the Button's own layout, and the Button looks the same.
+
+@cixzhang
diff --git a/docs/specs/components/Button/Button.spec.md b/docs/specs/components/Button/Button.spec.md
index 35ebe25d01..e955ed99ed 100644
--- a/docs/specs/components/Button/Button.spec.md
+++ b/docs/specs/components/Button/Button.spec.md
@@ -313,9 +313,8 @@ linked above.
## Open questions
-- **OQ1 — Does VoiceOver on macOS 14 WebKit compute the visible label as the
- Button's name?** (`checkable`) The label sits inside a `display: contents`
- content wrapper. A real-AT receipt under `spec:AST-009` would settle it.
+None. The content wrapper is a real box, so no `display: contents` element
+stands between the Button and its label for WebKit to drop the name through.
## Content boundary
diff --git a/packages/core/src/Button/Button.test.tsx b/packages/core/src/Button/Button.test.tsx
index 14d0f82d6e..4eec0d7252 100644
--- a/packages/core/src/Button/Button.test.tsx
+++ b/packages/core/src/Button/Button.test.tsx
@@ -775,6 +775,22 @@ describe('Button', () => {
await waitFor(() => expect(liveRegion).toHaveTextContent('Chargement'));
});
+ it('puts no display: contents element between the Button and its label', () => {
+ // WebKit before macOS 15 drops an accessible name computed through a
+ // `display: contents` element, so VoiceOver read the Button as unnamed.
+ render(
+ <Button label="Save" icon={<span>+</span>} endContent={<span>3</span>} />,
+ );
+ const button = screen.getByRole('button');
+ for (
+ let el = screen.getByText('Save').parentElement;
+ el != null && el !== button;
+ el = el.parentElement
+ ) {
+ expect(getComputedStyle(el).display).not.toBe('contents');
+ }
+ });
+
describe('in a narrow row', () => {
// jsdom has no layout, so these assert the computed declarations that
// produce the behavior. The real-browser widths are in the PR evidence.
@@ -790,6 +806,16 @@ describe('Button', () => {
expect(getComputedStyle(label).overflow).toBe('hidden');
});
+ it('lets the content box shrink too, so the label inside it truncates', () => {
+ render(<Button label="A very long button label that should truncate" />);
+ const box = screen.getByText(
+ 'A very long button label that should truncate',
+ ).parentElement!;
+ const style = getComputedStyle(box);
+ expect(style.minWidth).toBe('0');
+ expect(style.flexShrink).toBe('1');
+ });
+
it('keeps the default flex-shrink so a row can shrink the button', () => {
render(<Button label="Save" icon={<span>+</span>} />);
const style = getComputedStyle(screen.getByRole('button'));
diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsx
index 6f36a1d610..f06edfc73f 100644
--- a/packages/core/src/Button/Button.tsx
+++ b/packages/core/src/Button/Button.tsx
@@ -231,8 +231,24 @@ const styles = stylex.create({
justifyContent: 'center',
flexShrink: 0,
},
+ // A real box, not `display: contents`: WebKit before macOS 15 drops an
+ // accessible name computed through a `display: contents` element, so
+ // VoiceOver read a labelled Button as unnamed. The box takes the Button's
+ // own layout (it is the only in-flow child; the spinner overlay and the
+ // live region are absolutely positioned), so the content sits as before.
contentWrapper: {
- display: 'contents',
+ display: 'flex',
+ flexGrow: 1,
+ flexShrink: 1,
+ flexBasis: 'auto',
+ alignSelf: 'stretch',
+ flexDirection: 'inherit',
+ flexWrap: 'inherit',
+ alignItems: 'inherit',
+ justifyContent: 'inherit',
+ gap: 'inherit',
+ // Lets a narrow row shrink the box, so the label inside still truncates.
+ minWidth: 0,
},
labelText: {
overflow: 'hidden',