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] Add type button to accordion summary #39532

Merged
merged 8 commits into from
Oct 26, 2023
1 change: 1 addition & 0 deletions docs/data/joy/components/accordion/AccordionTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default function AccordionTransition() {
}}`
: `"${transition}"`
}>`}
language="jsx"
/>
</BrandingProvider>
</Box>
Expand Down
1 change: 1 addition & 0 deletions packages/mui-joy/src/Accordion/AccordionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const AccordionContext = React.createContext<
Partial<{
disabled: boolean;
expanded: boolean;
type: string;
KumarNitin19 marked this conversation as resolved.
Show resolved Hide resolved
toggle: (event: React.SyntheticEvent) => void;
accordionId: string;
}>
Expand Down
7 changes: 5 additions & 2 deletions packages/mui-joy/src/AccordionSummary/AccordionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { StyledListItemButton } from '../ListItemButton/ListItemButton';
import KeyboardArrowDown from '../internal/svg-icons/KeyboardArrowDown';

const useUtilityClasses = (ownerState: AccordionSummaryOwnerState) => {
const { disabled, expanded } = ownerState;
const { disabled, expanded, type } = ownerState;
const slots = {
root: ['root', disabled && 'disabled', expanded && 'expanded'],
button: ['button', disabled && 'disabled', expanded && 'expanded'],
button: ['button', disabled && 'disabled', expanded && 'expanded', type && 'type'],
KumarNitin19 marked this conversation as resolved.
Show resolved Hide resolved
indicator: ['indicator', disabled && 'disabled', expanded && 'expanded'],
};

Expand Down Expand Up @@ -102,6 +102,7 @@ const AccordionSummary = React.forwardRef(function AccordionSummary(inProps, ref
accordionId,
disabled = false,
expanded = false,
type = 'button',
toggle,
} = React.useContext(AccordionContext);

Expand All @@ -114,6 +115,7 @@ const AccordionSummary = React.forwardRef(function AccordionSummary(inProps, ref
disabled,
expanded,
variant,
type,
};

const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
Expand Down Expand Up @@ -148,6 +150,7 @@ const AccordionSummary = React.forwardRef(function AccordionSummary(inProps, ref
'aria-expanded': expanded ? 'true' : 'false',
'aria-controls': `${accordionId}-details`,
disabled,
type,
KumarNitin19 marked this conversation as resolved.
Show resolved Hide resolved
onClick: handleClick,
},
ownerState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ export interface AccordionSummaryOwnerState extends ApplyColorInversion<Accordio
* The expanded state of the accordion.
*/
expanded: boolean;
/**
* The type attribute specifies the type of button.
*/
type: string;
}