Skip to content
Open
Changes from 2 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
29 changes: 20 additions & 9 deletions packages/core/src/components/time-picker/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,11 @@ export class TimePicker {
elementContainer.focus({ preventScroll: true });

if (!this.isElementVisible(elementContainer, elementList)) {
elementContainer.scrollIntoView({
block: this.focusScrollAlignment,
});

if (this.focusScrollAlignment === 'end') {
elementList.scrollTop += 4;
} else {
elementList.scrollTop -= 4;
}
this.scrollElementIntoView(
elementContainer,
elementList,
this.focusScrollAlignment
);
}
}
}
Expand Down Expand Up @@ -462,6 +458,21 @@ export class TimePicker {
);
}

private scrollElementIntoView(
element: HTMLElement,
container: HTMLElement,
alignment: 'start' | 'end'
) {
const containerRect = container.getBoundingClientRect();
const elementRect = element.getBoundingClientRect();

if (alignment === 'end') {
container.scrollTop += elementRect.bottom - containerRect.bottom + 1;
} else {
container.scrollTop += elementRect.top - containerRect.top - 1;
}
}

private updateFocusedValue(value: number) {
const numberArray = this.getNumberArrayForUnit(this.focusedUnit);
const maxValue = numberArray[numberArray.length - 1];
Expand Down
Loading