diff --git a/assets/index.less b/assets/index.less index 998a6063c..2aeffefbc 100644 --- a/assets/index.less +++ b/assets/index.less @@ -131,9 +131,18 @@ border: 2px solid #e9e9e9; border-radius: 50%; cursor: pointer; + + &.@{prefixClass}-marks-dot { + border-color: #d6d6d6; + } + &-active { - border-color: tint(@primary-color, 50%); + &, + &.@{prefixClass}-marks-dot { + border-color: tint(@primary-color, 50%); + } } + &-reverse { margin-right: -4px; } diff --git a/src/Steps/Dot.tsx b/src/Steps/Dot.tsx index a8eaa4bef..f3b8f3456 100644 --- a/src/Steps/Dot.tsx +++ b/src/Steps/Dot.tsx @@ -5,13 +5,14 @@ import SliderContext from '../context'; export interface DotProps { prefixCls: string; + className?: string; value: number; style?: React.CSSProperties | ((dotValue: number) => React.CSSProperties); activeStyle?: React.CSSProperties | ((dotValue: number) => React.CSSProperties); } export default function Dot(props: DotProps) { - const { prefixCls, value, style, activeStyle } = props; + const { prefixCls, className, value, style, activeStyle } = props; const { min, max, direction, included, includedStart, includedEnd } = React.useContext(SliderContext); @@ -35,7 +36,7 @@ export default function Dot(props: DotProps) { ); diff --git a/src/Steps/index.tsx b/src/Steps/index.tsx index e3c235f85..e7b2e6781 100644 --- a/src/Steps/index.tsx +++ b/src/Steps/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import type { InternalMarkObj } from '../Marks'; import SliderContext from '../context'; import Dot from './Dot'; +import classNames from 'classnames'; export interface StepsProps { prefixCls: string; @@ -15,7 +16,7 @@ export default function Steps(props: StepsProps) { const { prefixCls, marks, dots, style, activeStyle } = props; const { min, max, step } = React.useContext(SliderContext); - const stepDots = React.useMemo(() => { + const { stepDots, marksValue } = React.useMemo(() => { const dotSet = new Set(); // Add marks @@ -23,6 +24,9 @@ export default function Steps(props: StepsProps) { dotSet.add(mark.value); }); + // Set marksValue + const uniqueMarksValue = Array.from(dotSet); + // Fill dots if (dots && step !== null) { let current = min; @@ -32,20 +36,31 @@ export default function Steps(props: StepsProps) { } } - return Array.from(dotSet); + return { + marksValue: uniqueMarksValue, + stepDots: Array.from(dotSet), + }; }, [min, max, step, dots, marks]); return (
- {stepDots.map((dotValue) => ( - - ))} + {stepDots.map((dotValue) => { + // Check whether it is a marks dot + const isMarksDot = marksValue.indexOf(dotValue) >= 0; + + return ( + + ); + })}
); } diff --git a/tests/marks.test.js b/tests/marks.test.js index 0d8c53c57..17f2063a5 100644 --- a/tests/marks.test.js +++ b/tests/marks.test.js @@ -19,12 +19,14 @@ describe('marks', () => { const marks = { 0: 0, 30: '30', 99: '', 100: '100' }; const { container } = render(); + expect(container.getElementsByClassName('rc-slider-marks-dot')).toHaveLength(3); expect(container.getElementsByClassName('rc-slider-mark-text')).toHaveLength(3); expect(container.getElementsByClassName('rc-slider-mark-text')[0].innerHTML).toBe('0'); expect(container.getElementsByClassName('rc-slider-mark-text')[1].innerHTML).toBe('30'); expect(container.getElementsByClassName('rc-slider-mark-text')[2].innerHTML).toBe('100'); const { container: container2 } = render(); + expect(container2.getElementsByClassName('rc-slider-marks-dot')).toHaveLength(3); expect(container2.getElementsByClassName('rc-slider-mark-text')).toHaveLength(3); expect(container2.getElementsByClassName('rc-slider-mark-text')[0].innerHTML).toBe('0'); expect(container2.getElementsByClassName('rc-slider-mark-text')[1].innerHTML).toBe('30');