diff --git a/components/Form/__test__/__snapshots__/form.spec.ts.snap b/components/Form/__test__/__snapshots__/form.spec.ts.snap index e47bedb8..efa44205 100644 --- a/components/Form/__test__/__snapshots__/form.spec.ts.snap +++ b/components/Form/__test__/__snapshots__/form.spec.ts.snap @@ -155,7 +155,7 @@ CustomEvent { } `; -exports[`Test: KForm > props: KForm initValue 1`] = `"
{"KInput":"KInput","KSwitch":true,"KRate":4,"KInputNumber":4,"KRadio":"3","KCheckbox":["2"],"KSelect":{"label":"不知明镜里","value":"不知","id":"3"},"KSelectString":"Huge","slider":43}
"`; +exports[`Test: KForm > props: KForm initValue 1`] = `"
{"KInput":"KInput","KSwitch":true,"KRate":4,"KInputNumber":4,"KRadio":"3","KCheckbox":["2"],"KSelect":{"label":"不知明镜里","value":"不知","id":"3"},"KSelectString":"Huge","slider":43}
"`; exports[`Test: KForm > props: KForm labelWidth 1`] = `"
"`; diff --git a/components/Slider/__test__/__snapshots__/slider.spec.ts.snap b/components/Slider/__test__/__snapshots__/slider.spec.ts.snap index c36796d1..b3460cc3 100644 --- a/components/Slider/__test__/__snapshots__/slider.spec.ts.snap +++ b/components/Slider/__test__/__snapshots__/slider.spec.ts.snap @@ -1,15 +1,17 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Test: KSlider > props: attrs 1`] = `"
"`; +exports[`Test: KSlider > props: attrs 1`] = `"
"`; -exports[`Test: KSlider > props: cls 1`] = `"
"`; +exports[`Test: KSlider > props: cls 1`] = `"
"`; -exports[`Test: KSlider > props: disabled 1`] = `"
"`; +exports[`Test: KSlider > props: disabled 1`] = `"
"`; -exports[`Test: KSlider > props: min and max 1`] = `"
"`; +exports[`Test: KSlider > props: min and max 1`] = `"
"`; -exports[`Test: KSlider > props: size 1`] = `"
"`; +exports[`Test: KSlider > props: showStops 1`] = `"
"`; -exports[`Test: KSlider > props: value 1`] = `"
"`; +exports[`Test: KSlider > props: size 1`] = `"
"`; -exports[`Test: KSlider > props: vertical 1`] = `"
"`; +exports[`Test: KSlider > props: value 1`] = `"
"`; + +exports[`Test: KSlider > props: vertical 1`] = `"
"`; diff --git a/components/Slider/__test__/slider.spec.ts b/components/Slider/__test__/slider.spec.ts index 1299a9db..b4f4ad19 100644 --- a/components/Slider/__test__/slider.spec.ts +++ b/components/Slider/__test__/slider.spec.ts @@ -161,6 +161,27 @@ describe('Test: KSlider', () => { expect(host.innerHTML).matchSnapshot(); }); + test('props: showStops', async () => { + const step: number = 10; + const min: number = 0; + const max: number = 100; + const instance = new KSlider({ + target: host, + props: { + step, + max, + min, + showStops: true + } + }); + expect(instance).toBeTruthy(); + await tick(); + expect(host.innerHTML.includes('k-slider--stop')).toBe(true); + const stopsElm = host.querySelectorAll('.k-slider--stop'); + expect(stopsElm.length).toBe((max - min) / step - 1); + expect(host.innerHTML).matchSnapshot(); + }); + test('props: cls', async () => { const instance = new KSlider({ target: host, diff --git a/components/Slider/src/index.svelte b/components/Slider/src/index.svelte index 38b42b87..869f0f2b 100644 --- a/components/Slider/src/index.svelte +++ b/components/Slider/src/index.svelte @@ -17,6 +17,7 @@ export let cls: KSliderProps['cls'] = undefined; export let showTooltip: KSliderProps['showTooltip'] = true; export let format: KSliderProps['format']; + export let showStops: KSliderProps['showStops'] = false; /*********************** KForm logic start ************************/ let disabledFrom = false; @@ -66,6 +67,12 @@ } } + // discrete showStops attr + let discreteNum = (max - min) / step - 1; + $: discreteDivsArray = showStops + ? Array.from({ length: discreteNum }, (_, index) => index + 1) + : []; + // current value let isDragging: boolean = false; let startX: number = 0; @@ -198,10 +205,28 @@ [`${prefixCls}--bar`]: !vertical, [`${prefixCls}--bar__vertical`]: vertical }); + $: discreteCls = clsx( + { + [`${prefixCls}--stop`]: !vertical, + [`${prefixCls}--stop__vertical`]: vertical + }, + `${prefixCls}--stop--${sizeInner}` + );