Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/curvy-carrots-feel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-elements": patch
---

fix: the param `index` of list scrollToPosition function should be `position`.
12 changes: 7 additions & 5 deletions packages/web-platform/web-elements/src/XList/XList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class XList extends HTMLElement {

scrollToPosition(
params: {
index: number;
position: number;
smooth?: boolean;
/**
* @description The offset of the content
Expand All @@ -73,12 +73,14 @@ export class XList extends HTMLElement {
offset = { left: params.offset, top: params.offset };
}

if (typeof params.index === 'number') {
if (params.index === 0) {
if (typeof params.position === 'number') {
if (params.position === 0) {
this.#getListContainer().scrollTop = 0;
this.#getListContainer().scrollLeft = 0;
} else if (params.index > 0 && params.index < this.childElementCount) {
const targetKid = this.children.item(params.index);
} else if (
params.position > 0 && params.position < this.childElementCount
) {
const targetKid = this.children.item(params.position);
if (targetKid instanceof HTMLElement) {
if (offset) {
offset = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export class XListAttributes
const initialScrollIndex = this.#dom.getAttribute('initial-scroll-index');

if (initialScrollIndex !== null) {
const index = parseFloat(initialScrollIndex);
const position = parseFloat(initialScrollIndex);
const scrollToInitialIndex = () => {
if (this.#dom.clientHeight === 0) {
// In Safari, there is the potential race condition between the browser's layout and clientWidth calculate.
// So, we have to use requestAnimationFrame to ensure that the code runs after the browser's layout.
requestAnimationFrame(scrollToInitialIndex);
} else {
this.#dom.scrollToPosition({ index });
this.#dom.scrollToPosition({ position });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function App() {
const handleScrollToPosition = () => {
ref.current?.invoke({
method: 'scrollToPosition',
params: { index: 10 },
params: { position: 10 },
}).exec();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'click',
() => {
document.querySelector('x-list').scrollToPosition({
index: 10,
position: 10,
});
},
);
Expand Down