Skip to content

Commit

Permalink
fix(Accordion) : fix expanding breaks the AccordionDetails children t…
Browse files Browse the repository at this point in the history
…ab index.

Closes mui#40116
  • Loading branch information
Shreypatel13ll committed Aug 9, 2024
1 parent b505fd7 commit ed36297
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/mui-joy/src/AccordionDetails/AccordionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,33 @@ const AccordionDetails = React.forwardRef(function AccordionDetails(inProps, ref
);
elements.forEach((elm) => {
if (expanded) {
// Accordion is expanded
const prevTabIndex = elm.getAttribute('data-prev-tabindex');
const currentTabIndex = elm.getAttribute('tabindex');

if (currentTabIndex && prevTabIndex) {
// restore tabindex
if (prevTabIndex === 'unset') {
// If 'unset', this element did not originally have a tabindex, so remove it.
elm.removeAttribute('tabindex');
} else if (prevTabIndex !== null) {
// Restore the original tabindex value and remove the tracking attribute.
elm.setAttribute('tabindex', prevTabIndex);
elm.removeAttribute('data-prev-tabindex');
}

if (!prevTabIndex && !currentTabIndex) {
elm.removeAttribute('tabindex');
}
} else {
elm.setAttribute('data-prev-tabindex', elm.getAttribute('tabindex') || '');
// Accordion is collapsed
const currentTabIndex = elm.getAttribute('tabindex');
if (currentTabIndex !== null) {
// Save the current tabindex for restoration later when expanded.
elm.setAttribute('data-prev-tabindex', currentTabIndex);
} else {
// Use 'unset' to track elements that originally had no tabindex.
elm.setAttribute('data-prev-tabindex', 'unset');
}
elm.setAttribute('tabindex', '-1');
}
});
}
}, [expanded]);


const externalForwardedProps = { ...other, component, slots, slotProps };

const ownerState = {
Expand Down

0 comments on commit ed36297

Please sign in to comment.