Skip to content

Commit

Permalink
[joy-ui][Accordion] Fix incorrect display of classname (mui#38695)
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 authored and mnajdova committed Sep 8, 2023
1 parent 8385f91 commit a8797ce
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/pages/joy-ui/api/accordion-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"import AccordionGroup from '@mui/joy/AccordionGroup';",
"import { AccordionGroup } from '@mui/joy';"
],
"styles": { "classes": ["root"], "globalClasses": {}, "name": "MuiAccordionGroup" },
"styles": { "classes": [], "globalClasses": {}, "name": "MuiAccordionGroup" },
"slots": [
{
"name": "root",
Expand All @@ -62,6 +62,7 @@
"class": ".MuiAccordionGroup-root"
}
],
"classes": { "classes": ["sizeLg", "sizeMd", "sizeSm"], "globalClasses": {} },
"spread": true,
"themeDefaultProps": true,
"muiName": "JoyAccordionGroup",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
"description": "The <a href=\"https://mui.com/joy-ui/main-features/global-variants/\">global variant</a> to use."
}
},
"classDescriptions": { "root": { "description": "Class name applied to the root element." } },
"classDescriptions": {
"root": { "description": "Class name applied to the root element." },
"sizeSm": {
"description": "Class name applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>size=\"sm\"</code>"
},
"sizeMd": {
"description": "Class name applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>size=\"md\"</code>"
},
"sizeLg": {
"description": "Class name applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>size=\"lg\"</code>"
}
},
"slotDescriptions": { "root": "The component that renders the root." }
}
19 changes: 19 additions & 0 deletions packages/mui-joy/src/AccordionGroup/AccordionGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from 'test/utils';
import { ThemeProvider } from '@mui/joy/styles';
import AccordionGroup, { accordionGroupClasses as classes } from '@mui/joy/AccordionGroup';
Expand All @@ -21,4 +22,22 @@ describe('<AccordionGroup />', () => {
},
},
}));

describe('classes', () => {
(
[
{ size: 'sm', class: classes.sizeSm },
{ size: 'md', class: classes.sizeMd },
{ size: 'lg', class: classes.sizeLg },
] as const
).forEach((sizeConfig) => {
it(`should have ${sizeConfig.class} class for ${sizeConfig.size} size `, () => {
const { getByTestId } = render(
<AccordionGroup data-testid="root" size={sizeConfig.size} />,
);

expect(getByTestId('root')).to.have.class(sizeConfig.class);
});
});
});
});
2 changes: 1 addition & 1 deletion packages/mui-joy/src/AccordionGroup/AccordionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const useUtilityClasses = (ownerState: AccordionGroupOwnerState) => {
'root',
variant && `variant${capitalize(variant)}`,
color && `color${capitalize(color)}`,
size && `size${capitalize(size)}}`,
size && `size${capitalize(size)}`,
],
};

Expand Down
9 changes: 9 additions & 0 deletions packages/mui-joy/src/AccordionGroup/accordionGroupClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { generateUtilityClass, generateUtilityClasses } from '../className';
export interface AccordionGroupClasses {
/** Class name applied to the root element. */
root: string;
/** Class name applied to the root element if `size="sm"`. */
sizeSm: string;
/** Class name applied to the root element if `size="md"`. */
sizeMd: string;
/** Class name applied to the root element if `size="lg"`. */
sizeLg: string;
}

export type AccordionGroupClassKey = keyof AccordionGroupClasses;
Expand All @@ -13,6 +19,9 @@ export function getAccordionGroupUtilityClass(slot: string): string {

const accordionGroupClasses: AccordionGroupClasses = generateUtilityClasses('MuiAccordionGroup', [
'root',
'sizeSm',
'sizeMd',
'sizeLg',
]);

export default accordionGroupClasses;

0 comments on commit a8797ce

Please sign in to comment.