Skip to content

Commit

Permalink
feat(slider): fix incorrect dot pos caused by repeated init (#3085)
Browse files Browse the repository at this point in the history
* feat(slider): fix incorrect dot pos caused by repeated init

each time init is called, the dots are set to the defaultValue position. Added a flag to filter

fix #3083

* docs(slider): update readme
  • Loading branch information
jby0107 authored Aug 20, 2024
1 parent 0d31830 commit b83cf02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/slider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ t-class-cursor | 游标样式类

## FAQ

当 slider 外层使用 `hidden` 包裹,需要在 `hidden = false` 时,重新调用组件的 `init` 方法,才能正常渲染。如下:
当 slider 外层使用 `hidden` 包裹,需要在 `hidden = false` 时,重新调用组件的 `init` 方法,才能正常渲染(在t-popup/t-dialog中同理)。如下:

```html
<t-slider id="slider" />
Expand Down
8 changes: 8 additions & 0 deletions src/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type dataType = {
prefix: string;
isVisibleToScreenReader: boolean;
identifier: number[];
__inited: boolean;
};

interface boundingClientRect {
Expand All @@ -46,6 +47,10 @@ export default class Slider extends SuperComponent {
`${prefix}-class-cursor`,
];

options = {
pureDataPattern: /^__/,
};

properties = props;

controlledProps = [
Expand Down Expand Up @@ -76,6 +81,7 @@ export default class Slider extends SuperComponent {
prefix,
isVisibleToScreenReader: false,
identifier: [-1, -1],
__inited: false,
};

observers = {
Expand Down Expand Up @@ -218,6 +224,7 @@ export default class Slider extends SuperComponent {
}

async init() {
if (this.data.__inited) return;
const line: boundingClientRect = await getRect(this, '#sliderLine');
const { blockSize } = this.data;
const { theme, vertical } = this.properties;
Expand All @@ -238,6 +245,7 @@ export default class Slider extends SuperComponent {
maxRange,
initialLeft,
initialRight,
__inited: true,
});
this.bus.emit('initial');
}
Expand Down

0 comments on commit b83cf02

Please sign in to comment.