Skip to content

Commit

Permalink
data-checked
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Oct 11, 2024
1 parent 7485733 commit e95cf36
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/data/components/menu/CheckboxItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const Indicator = styled(Menu.CheckboxItemIndicator)(
border-radius: 2px;
&[data-checkbox-item-checked] {
&[data-checked] {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[700]};
box-shadow: 0 0 0 2px ${theme.palette.mode === 'dark' ? grey[900] : '#fff'} inset;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/components/menu/CheckboxItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const Indicator = styled(Menu.CheckboxItemIndicator)(
border-radius: 2px;
&[data-checkbox-item-checked] {
&[data-checked] {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[700]};
box-shadow: 0 0 0 2px ${theme.palette.mode === 'dark' ? grey[900] : '#fff'} inset;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/components/menu/RadioItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const Indicator = styled(Menu.RadioItemIndicator)(
box-sizing: border-box;
border-radius: 50%;
&[data-radio-item-checked] {
&[data-checked] {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[700]};
box-shadow: 0 0 0 2px ${theme.palette.mode === 'dark' ? grey[900] : '#fff'} inset;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/components/menu/RadioItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const Indicator = styled(Menu.RadioItemIndicator)(
box-sizing: border-box;
border-radius: 50%;
&[data-radio-item-checked] {
&[data-checked] {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[700]};
box-shadow: 0 0 0 2px ${theme.palette.mode === 'dark' ? grey[900] : '#fff'} inset;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('<Menu.CheckboxItem />', () => {

const item = getByRole('menuitemcheckbox');
expect(item).to.have.attribute('aria-checked', ariaChecked);
expect(item).to.have.attribute(`data-checkbox-item-${dataState}`, '');
expect(item).to.have.attribute(`data-${dataState}`, '');
}),
);

Expand All @@ -170,12 +170,12 @@ describe('<Menu.CheckboxItem />', () => {
await user.click(item);

expect(item).to.have.attribute('aria-checked', 'true');
expect(item).to.have.attribute('data-checkbox-item-checked', '');
expect(item).to.have.attribute('data-checked', '');

await user.click(item);

expect(item).to.have.attribute('aria-checked', 'false');
expect(item).to.have.attribute('data-checkbox-item-unchecked', '');
expect(item).to.have.attribute('data-unchecked', '');
});

it(`toggles the checked state when Space is pressed`, async () => {
Expand All @@ -202,10 +202,10 @@ describe('<Menu.CheckboxItem />', () => {
});

await user.keyboard(`[Space]`);
expect(item).to.have.attribute('data-checkbox-item-checked', '');
expect(item).to.have.attribute('data-checked', '');

await user.keyboard(`[Space]`);
expect(item).to.have.attribute('data-checkbox-item-unchecked', '');
expect(item).to.have.attribute('data-unchecked', '');
});

it(`toggles the checked state and closes the menu when Enter is pressed`, async () => {
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('<Menu.CheckboxItem />', () => {

expect(queryByRole('menu', { hidden: false })).to.equal(null);
await user.click(trigger);
expect(item).to.have.attribute('data-checkbox-item-checked', '');
expect(item).to.have.attribute('data-checked', '');
});

it('calls `onCheckedChange` when the item is clicked', async () => {
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('<Menu.CheckboxItem />', () => {

const itemAfterReopen = getByRole('menuitemcheckbox');
expect(itemAfterReopen).to.have.attribute('aria-checked', 'true');
expect(itemAfterReopen).to.have.attribute('data-checkbox-item-checked');
expect(itemAfterReopen).to.have.attribute('data-checked');
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/mui-base/src/Menu/RadioItem/MenuRadioItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('<Menu.RadioItem />', () => {
await user.click(item);

expect(item).to.have.attribute('aria-checked', 'true');
expect(item).to.have.attribute('data-radio-item-checked', '');
expect(item).to.have.attribute('data-checked', '');
});

['Space', 'Enter'].forEach((key) => {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('<Menu.RadioItem />', () => {
});

await user.keyboard(`[${key}]`);
expect(item).to.have.attribute('data-radio-item-checked', '');
expect(item).to.have.attribute('data-checked', '');
});
});

Expand Down Expand Up @@ -256,7 +256,7 @@ describe('<Menu.RadioItem />', () => {

const itemAfterReopen = getByRole('menuitemradio');
expect(itemAfterReopen).to.have.attribute('aria-checked', 'true');
expect(itemAfterReopen).to.have.attribute('data-radio-item-checked', '');
expect(itemAfterReopen).to.have.attribute('data-checked', '');
});
});

Expand Down
19 changes: 3 additions & 16 deletions packages/mui-base/src/Menu/utils/styleHookMapping.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import type { CustomStyleHookMapping } from '../../utils/getStyleHookProps';

export const radioItemMapping: CustomStyleHookMapping<{ checked: boolean }> = {
export const itemMapping: CustomStyleHookMapping<{ checked: boolean }> = {
checked(value): Record<string, string> {
if (value) {
return {
'data-radio-item-checked': '',
'data-checked': '',
};
}
return {
'data-radio-item-unchecked': '',
};
},
};

export const checkboxItemMapping: CustomStyleHookMapping<{ checked: boolean }> = {
checked(value): Record<string, string> {
if (value) {
return {
'data-checkbox-item-checked': '',
};
}
return {
'data-checkbox-item-unchecked': '',
'data-unchecked': '',
};
},
};

0 comments on commit e95cf36

Please sign in to comment.