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

fix(slider): fix marks reactive #1739

Merged
merged 1 commit into from
Feb 12, 2025
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
4 changes: 4 additions & 0 deletions src/slider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import _Slider from './slider';
import { withInstall, WithInstallType } from '../shared';

import './style';
import { TdSliderProps } from './type';

export * from './type';
export type SliderProps = TdSliderProps;

export const Slider: WithInstallType<typeof _Slider> = withInstall(_Slider);
export default Slider;
28 changes: 18 additions & 10 deletions src/slider/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default defineComponent({
watch(
() => innerValue.value,
(val) => {
if (props.range) {
if (props.range && Array.isArray(val)) {
const left = (state.maxRange * (val[0] - props.min)) / scope.value;
const right = (state.maxRange * (props.max - val[1])) / scope.value;
// 因为要计算点相对于线的绝对定位,所以要取整条线的长度而非可滑动的范围
Expand All @@ -71,6 +71,14 @@ export default defineComponent({
}
},
);

watch(
() => props.marks,
(val) => {
handleMask(val);
},
);

const rootRef = ref<HTMLDivElement>();

const classes = computed(() => [
Expand Down Expand Up @@ -279,7 +287,7 @@ export default defineComponent({
}
};

const readerMinText = () => {
const renderMinText = () => {
if (!props.showExtremeValue) {
return null;
}
Expand All @@ -294,7 +302,7 @@ export default defineComponent({
}
return <text class={textClass}>{props.label ? getValue(props.label, props.min) : props.min}</text>;
};
const readerMaxText = () => {
const renderMaxText = () => {
if (!props.showExtremeValue) {
return null;
}
Expand All @@ -305,7 +313,7 @@ export default defineComponent({
return <text class={textClass}>{props.label ? getValue(props.label, props.max) : props.max}</text>;
};

const readerScale = () => {
const renderScale = () => {
if (!state.isScale) {
return null;
}
Expand Down Expand Up @@ -336,7 +344,7 @@ export default defineComponent({
);
});
};
const readerLineSingle = () => {
const renderLineSingle = () => {
return (
<div
class={[
Expand Down Expand Up @@ -369,7 +377,7 @@ export default defineComponent({
</div>
);
};
const readerLineRange = () => {
const renderLineRange = () => {
return (
<div
class={[
Expand Down Expand Up @@ -424,16 +432,16 @@ export default defineComponent({
return () => {
return (
<div ref={rootRef} class={classes.value}>
{readerMinText()}
{renderMinText()}
<div
ref={sliderLine}
class={sliderLineClasses.value}
onClick={props.range ? handleRangeClick : handleSingleClick}
>
{readerScale()}
{props.range ? readerLineRange() : readerLineSingle()}
{renderScale()}
{props.range ? renderLineRange() : renderLineSingle()}
</div>
{readerMaxText()}
{renderMaxText()}
</div>
);
};
Expand Down
Loading