Skip to content

Commit 917e39f

Browse files
fix(dropdown,box): drop menu-item prop leak; restore Box filter coverage
Two follow-ups from the PR 1150 review: - Dropdown: DropdownMenuItemStyled spread `{...item}`, forwarding the Item fields (name/selected/label) onto the <li> as invalid DOM attributes. The spread was redundant — onClick already flows through getItemProps and label is rendered as children — so it is removed. Verified no consumer repo or test selects menu items by those attributes. (@ts-nocheck left in place; making the class compile-visible is tracked separately.) - Box: restore Box.test.tsx as behavioural coverage for the shouldForwardProp filter — the one place the migration diverges from the mechanical rename. Asserts the migration contract (styled-system props stay out of the HTML), that genuine a11y attributes + click handlers still reach the element, and that polymorphic `as` works. Drives the click with userEvent. tsc clean, 477/477 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent fff9c13 commit 917e39f

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { render, screen } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
3+
import { Box } from './Box';
4+
5+
describe('Box', () => {
6+
it('keeps design-system style props out of the rendered HTML', () => {
7+
// Under styled-components v6 (which forwards unknown props to the DOM),
8+
// Box must filter its open-ended styled-system props so they never surface
9+
// as invalid HTML attributes on the element.
10+
render(
11+
<Box
12+
mt={2}
13+
bg="backgroundLevel1"
14+
flexDirection="column"
15+
alignItems="center"
16+
justifyContent="space-between"
17+
data-testid="b"
18+
/>,
19+
);
20+
const el = screen.getByTestId('b');
21+
expect(el.hasAttribute('mt')).toBe(false);
22+
expect(el.hasAttribute('bg')).toBe(false);
23+
expect(el.hasAttribute('flexDirection')).toBe(false);
24+
expect(el.hasAttribute('flexdirection')).toBe(false);
25+
expect(el.hasAttribute('alignItems')).toBe(false);
26+
expect(el.hasAttribute('justifyContent')).toBe(false);
27+
});
28+
29+
it('forwards accessibility attributes and click handlers to the element', async () => {
30+
const onClick = jest.fn();
31+
render(
32+
<Box
33+
id="my-box"
34+
role="region"
35+
aria-label="a box"
36+
data-custom="keep"
37+
onClick={onClick}
38+
data-testid="b"
39+
/>,
40+
);
41+
const el = screen.getByTestId('b');
42+
expect(el.getAttribute('id')).toBe('my-box');
43+
expect(el.getAttribute('role')).toBe('region');
44+
expect(el.getAttribute('aria-label')).toBe('a box');
45+
expect(el.getAttribute('data-custom')).toBe('keep');
46+
await userEvent.click(el);
47+
expect(onClick).toHaveBeenCalledTimes(1);
48+
});
49+
50+
it('renders as the element given by the "as" prop', () => {
51+
render(<Box as="section" data-testid="b" />);
52+
expect(screen.getByTestId('b').tagName).toBe('SECTION');
53+
});
54+
});

src/lib/components/dropdown/Dropdown.component.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ function Dropdown({
163163
<DropdownMenuItemStyled
164164
className="menu-item-label"
165165
key={item.label}
166-
{...item}
167166
{...getItemProps({
168167
item,
169168
index,

0 commit comments

Comments
 (0)