Skip to content

Commit

Permalink
use recommended approach
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Sep 27, 2022
1 parent 5b1a229 commit 20ce901
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/x-date-pickers/src/CalendarPicker/CalendarPicker.tsx
Expand Up @@ -437,15 +437,12 @@ export const CalendarPicker = React.forwardRef(function CalendarPicker<TDate>(
},
);

const prevOpenViewRef = React.useRef(openView);
React.useEffect(() => {
// Set focus to the button when switching from a view to another
if (prevOpenViewRef.current === openView) {
return;
}
prevOpenViewRef.current = openView;
const [prevOpenView, setPrevOpenView] = React.useState(openView);

if (prevOpenView !== openView) {
handleFocusedViewChange(openView)(true);
}, [openView, handleFocusedViewChange]);
setPrevOpenView(openView);
}

return (
<CalendarPickerRoot
Expand Down

0 comments on commit 20ce901

Please sign in to comment.