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

support aria #260

Merged
merged 1 commit into from
May 31, 2017
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
2 changes: 1 addition & 1 deletion examples/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const handle = (props) => {
placement="top"
key={index}
>
<Handle {...restProps} />
<Handle value={value} {...restProps} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ant-design 少个value,break change,rc-slider 要发大版本。

到 ant-design 那边也提个PR WIP 修下吧

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</Tooltip>
);
};
Expand Down
26 changes: 19 additions & 7 deletions src/Handle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ import PropTypes from 'prop-types';
export default class Handle extends React.Component {
render() {
const {
className, vertical, offset, handleStyle, ...restProps,
className, vertical, offset, handleStyle, disabled, min, max, value, ...restProps,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里会导致下面的 handle div 少一个 disabled 属性吧

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

div 不应该有 disabled 属性吧 @paranoidjk

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恩,是的,看来是之前的代码有bug,那这里会导致snapshot都要更新了
https://stackoverflow.com/questions/6307586/how-should-disabled-div-act

} = this.props;
const style = vertical ? { bottom: `${offset}%` } : { left: `${offset}%` };

const elStyle = {
...style,
...handleStyle,
};
return <div {...restProps} className={className} style={elStyle} />;
const style = vertical ? { bottom: `${offset}%` } : { left: `${offset}%` };
const elStyle = { ...style, ...handleStyle };
return (
<div
role="slider"
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value}
aria-disabled={disabled}
{...restProps}
className={className}
style={elStyle}
/>
);
}
}

Expand All @@ -21,4 +29,8 @@ Handle.propTypes = {
vertical: PropTypes.bool,
offset: PropTypes.number,
handleStyle: PropTypes.object,
disabled: PropTypes.bool,
min: PropTypes.number,
max: PropTypes.number,
value: PropTypes.number,
};
4 changes: 4 additions & 0 deletions src/Range.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ class Range extends React.Component {
vertical,
included,
disabled,
min,
max,
handle: handleGenerator,
} = this.props;

Expand All @@ -298,6 +300,8 @@ class Range extends React.Component {
value: v,
dragging: handle === i,
index: i,
min,
max,
disabled,
ref: h => this.saveHandle(i, h),
}));
Expand Down
4 changes: 4 additions & 0 deletions src/Slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class Slider extends React.Component {
disabled,
minimumTrackStyle,
handleStyle,
min,
max,
handle: handleGenerator,
} = this.props;
const { value, dragging } = this.state;
Expand All @@ -123,6 +125,8 @@ class Slider extends React.Component {
value,
dragging,
disabled,
min,
max,
handleStyle,
ref: h => this.saveHandle(0, h),
});
Expand Down
1 change: 0 additions & 1 deletion src/common/createSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export default function createSlider(Component) {
marks: {},
handle({ index, ...restProps }) {
delete restProps.dragging;
delete restProps.value;
return <Handle {...restProps} key={index} />;
},
onBeforeChange: noop,
Expand Down
1 change: 1 addition & 0 deletions src/createSliderWithTooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function createSliderWithTooltip(Component) {
>
<Handle
{...restProps}
value={value}
onMouseEnter={() => this.handleTooltipVisibleChange(index, true)}
onMouseLeave={() => this.handleTooltipVisibleChange(index, false)}
/>
Expand Down
30 changes: 30 additions & 0 deletions tests/__snapshots__/Range.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,36 @@ exports[`Range should render Multi-Range with correct DOM structure 1`] = `
<div
class="rc-slider-step" />
<div
aria-disabled="false"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="0"
class="rc-slider-handle rc-slider-handle-1"
role="slider"
style="left:0%;" />
<div
aria-disabled="false"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="0"
class="rc-slider-handle rc-slider-handle-2"
role="slider"
style="left:0%;" />
<div
aria-disabled="false"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="0"
class="rc-slider-handle rc-slider-handle-3"
role="slider"
style="left:0%;" />
<div
aria-disabled="false"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="0"
class="rc-slider-handle rc-slider-handle-4"
role="slider"
style="left:0%;" />
<div
class="rc-slider-mark" />
Expand All @@ -42,10 +62,20 @@ exports[`Range should render Range with correct DOM structure 1`] = `
<div
class="rc-slider-step" />
<div
aria-disabled="false"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="0"
class="rc-slider-handle rc-slider-handle-1"
role="slider"
style="left:0%;" />
<div
aria-disabled="false"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="0"
class="rc-slider-handle rc-slider-handle-2"
role="slider"
style="left:0%;" />
<div
class="rc-slider-mark" />
Expand Down
5 changes: 5 additions & 0 deletions tests/__snapshots__/Slider.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ exports[`Slider should render Slider with correct DOM structure 1`] = `
<div
class="rc-slider-step" />
<div
aria-disabled="false"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="0"
class="rc-slider-handle"
role="slider"
style="left:0%;" />
<div
class="rc-slider-mark" />
Expand Down