Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[joy-ui][Accordion] Fix incorrect display of classname #38695

Merged
merged 6 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also notice variant and color classes are missing here. I'll add them in follow-up PR as it's beyond scope of this PR.

/** 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;