8000 Added feature of setting the crosur to default rather than grab by saharme · Pull Request #766 · react-component/slider · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added feature of setting the crosur to default rather than grab #766

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
36 changes: 36 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions docs/examples/handle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<SliderTooltip
Expand All @@ -30,6 +30,10 @@ export default () => (
<p>Slider with custom handle</p>
<Slider min={0} max={20} defaultValue={3} handle={handle} />
</div>
<div style={wrapperStyle}>
<p>Slider with default cursor</p>
<Slider min={0} max={20} defaultValue={3} isUseDefaultCursor={true} handle={handle} />
</div>
<div style={wrapperStyle}>
<p>Reversed Slider with custom handle</p>
<Slider min={0} max={20} reverse defaultValue={3} handle={handle} />
Expand All @@ -40,7 +44,7 @@ export default () => (
</div>
<div style={wrapperStyle}>
<p>Range with custom tooltip</p>
<Range min={0} max={20} defaultValue={[3, 10]} tipFormatter={value => `${value}%`} />
<Range min={0} max={20} defaultValue={[3, 10]} tipFormatter={(value) => `${value}%`} />
</div>
</div>
);
4 changes: 3 additions & 1 deletion src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -221,6 +222,7 @@ class Slider extends React.Component<SliderProps, SliderState> {
minimumTrackStyle,
trackStyle,
handleStyle,
isUseDefaultCursor,
tabIndex,
ariaLabelForHandle,
ariaLabelledByForHandle,
Expand All @@ -234,7 +236,7 @@ class Slider extends React.Component<SliderProps, SliderState> {
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,
Expand Down
6 changes: 6 additions & 0 deletions tests/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ describe('Slider', () => {
expect(trackStyle.width).toMatch('50%');
});

it('should render Slider with default cursor', () => {
const wrapper = mount(<Slider value={50} isUseDefaultCursor={true} />);
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(<Slider value={50} startPoint={20} />);
expect(wrapper.state('value')).toBe(50);
Expand Down
0