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

[DateTimePicker] Scroll to Digital Clock section only when selection changes #9434

Merged
merged 2 commits into from
Jun 27, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const MultiSectionDigitalClockSection = React.forwardRef(
) {
const containerRef = React.useRef<HTMLUListElement>(null);
const handleRef = useForkRef(ref, containerRef);
const previousSelected = React.useRef<HTMLElement | null>(null);

const props = useThemeProps({
props: inProps,
Expand Down Expand Up @@ -155,9 +156,14 @@ export const MultiSectionDigitalClockSection = React.forwardRef(
const selectedItem = containerRef.current.querySelector<HTMLElement>(
'[role="option"][aria-selected="true"]',
);
if (!selectedItem) {
if (!selectedItem || previousSelected.current === selectedItem) {
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
// Handle setting the ref to null if the selected item is ever reset via UI
if (previousSelected.current !== selectedItem) {
previousSelected.current = selectedItem;
}
return;
}
previousSelected.current = selectedItem;
if (active && autoFocus) {
selectedItem.focus();
}
Expand Down