diff --git a/README.md b/README.md index cf74bdcde..ab9540d12 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ The following APIs are shared by Slider and Range. | value | number | - | Set current value of slider. | | startPoint | number | `undefined` | Track starts from this value. If `undefined`, `min` is used. | | tabIndex | number | `0` | Set the tabIndex of the slider handle. | +| isUseDefaultCursor | boolean | false | Set the cursor to default rather than grab. | | ariaLabelForHandle | string | - | Set the `aria-label` attribute on the slider handle. | | ariaLabelledByForHandle | string | - | Set the `aria-labelledby` attribute on the slider handle. | | ariaValueTextFormatterForHandle | (value) => string | - | A function to set the `aria-valuetext` attribute on the slider handle. It receives the current value of the slider and returns a formatted string describing the value. See [WAI-ARIA Authoring Practices 1.1](https://www.w3.org/TR/wai-aria-practices-1.1/#slider) for more information. | diff --git a/assets/index.less b/assets/index.less index 922fcc855..2a3c300b2 100644 --- a/assets/index.less +++ b/assets/index.less @@ -85,6 +85,42 @@ } } + &-handle-default { + position: absolute; + width: 14px; + height: 14px; + cursor: default; + margin-top: -5px; + border-radius: 50%; + border: solid 2px tint(@primary-color, 50%); + background-color: #fff; + touch-action: pan-x; + + &-dragging&-dragging&-dragging { + border-color: tint(@primary-color, 20%); + box-shadow: 0 0 0 5px tint(@primary-color, 50%); + } + + &:focus { + outline: none; + } + + &-click-focused:focus { + border-color: tint(@primary-color, 50%); + box-shadow: unset; + } + + &:hover { + border-color: tint(@primary-color, 20%); + } + + &:active { + border-color: tint(@primary-color, 20%); + box-shadow: 0 0 5px tint(@primary-color, 20%); + cursor: default; + } + } + &-mark { position: absolute; top: 18px; diff --git a/docs/examples/handle.jsx b/docs/examples/handle.jsx index b9b3095f1..0d99cab2f 100644 --- a/docs/examples/handle.jsx +++ b/docs/examples/handle.jsx @@ -7,7 +7,7 @@ const { createSliderWithTooltip } = Slider; const Range = createSliderWithTooltip(Slider.Range); const { Handle } = Slider; -const handle = props => { +const handle = (props) => { const { value, dragging, index, ...restProps } = props; return ( (

Slider with custom handle

+
+

Slider with default cursor

+ +

Reversed Slider with custom handle

@@ -40,7 +44,7 @@ export default () => (

Range with custom tooltip

- `${value}%`} /> + `${value}%`} />
); diff --git a/src/Slider.tsx b/src/Slider.tsx index f3c98d2ae..11e5e73a9 100644 --- a/src/Slider.tsx +++ b/src/Slider.tsx @@ -22,6 +22,7 @@ export interface SliderProps extends GenericSliderProps { minimumTrackStyle?: React.CSSProperties; trackStyle?: React.CSSProperties; handleStyle?: React.CSSProperties; + isUseDefaultCursor?: boolean; tabIndex?: number; ariaLabelForHandle?: string; ariaLabelledByForHandle?: string; @@ -221,6 +222,7 @@ class Slider extends React.Component { minimumTrackStyle, trackStyle, handleStyle, + isUseDefaultCursor, tabIndex, ariaLabelForHandle, ariaLabelledByForHandle, @@ -234,7 +236,7 @@ class Slider extends React.Component { const { value, dragging } = this.state; const offset = this.calcOffset(value); const handle = handleGenerator({ - className: `${prefixCls}-handle`, + className: isUseDefaultCursor ? `${prefixCls}-handle-default` : `${prefixCls}-handle`, prefixCls, vertical, offset, diff --git a/tests/Slider.test.js b/tests/Slider.test.js index 9db8ea27b..94ef96dd5 100644 --- a/tests/Slider.test.js +++ b/tests/Slider.test.js @@ -23,6 +23,12 @@ describe('Slider', () => { expect(trackStyle.width).toMatch('50%'); }); + it('should render Slider with default cursor', () => { + const wrapper = mount(); + expect(wrapper.state('value')).toBe(50); + expect(wrapper.find('.rc-slider-handle-default').exists()).toBeTruthy(); + }); + it('should render Slider correctly where value > startPoint', () => { const wrapper = mount(); expect(wrapper.state('value')).toBe(50);