Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/primitives/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ const ColumnStyles: NodeStyles = {
gap: 30,
};

function scrollToIndex(this: ElementNode, index: number) {
function scrollToIndex(this: ElementNode, index: number, options?: {noFocus?: boolean}) {
this.selected = index;
scrollColumn(index, this);
this.children[index]?.setFocus();
if (!options?.noFocus) {
this.children[index]?.setFocus();
}
}

const onUp = handleNavigation('up');
Expand Down
4 changes: 2 additions & 2 deletions src/primitives/Lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ function createLazy<T>(
Array.isArray(props.each) ? props.each.slice(0, offset()) : [],
);

function lazyScrollToIndex(this: lngp.NavigableElement, index: number) {
function lazyScrollToIndex(this: lngp.NavigableElement, index: number, options?: {noFocus?: boolean}) {
setOffset(Math.max(index, 0) + buffer())
queueMicrotask(() => viewRef.scrollToIndex(index));
queueMicrotask(() => viewRef.scrollToIndex(index, options));
}

const updateOffset = (_event: KeyboardEvent, container: lng.ElementNode) => {
Expand Down
6 changes: 4 additions & 2 deletions src/primitives/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ const RowStyles: NodeStyles = {
gap: 30,
};

function scrollToIndex(this: ElementNode, index: number) {
function scrollToIndex(this: ElementNode, index: number, options?: {noFocus?: boolean}) {
this.selected = index;
scrollRow(index, this);
this.children[index]?.setFocus();
if (!options?.noFocus) {
this.children[index]?.setFocus();
}
}

const onLeft = handleNavigation('left');
Expand Down
6 changes: 5 additions & 1 deletion src/primitives/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export interface NavigableProps extends NodeProps {
// @ts-expect-error animationSettings is not identical - weird
export interface NavigableElement extends ElementNode, NavigableProps {
selected: number;
scrollToIndex: (this: NavigableElement, index: number) => void;
scrollToIndex: (
this: NavigableElement,
index: number,
options?: { noFocus?: boolean },
) => void;
}

export interface NavigableStyleProperties {
Expand Down