Skip to content
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
25 changes: 19 additions & 6 deletions src/Range.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,38 @@ class Range extends React.Component {
})
});

const getTrackClassName = (i) => classNames({
[`${prefixCls}-track`]: true,
[`${prefixCls}-track-${i}`]: true,
});

const tracks = bounds.slice(0, -1).map((_, index) => {
const i = index + 1;
const trackClassName = classNames({
[`${prefixCls}-track`]: true,
[`${prefixCls}-track-${i}`]: true,
});
return (
<Track
className={trackClassName}
className={getTrackClassName(i)}
vertical={vertical}
included={included}
offset={offsets[i - 1]}
length={offsets[i] - offsets[i - 1]}
style={trackStyle[index]}
style={trackStyle[index + 1]}
key={i}
/>
);
});

tracks.unshift(
<Track
className={getTrackClassName(0)}
vertical={vertical}
included={included}
offset={0}
length={offsets[0]}
style={trackStyle[0]}
key={0}
/>
);

return { tracks, handles };
}
}
Expand Down
20 changes: 14 additions & 6 deletions tests/Range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ describe('Range', () => {
expect(wrapper.find('.rc-slider-handle > .rc-slider-handle').at(0).props().style.left).toMatch('0%');
expect(wrapper.find('.rc-slider-handle > .rc-slider-handle').at(1).props().style.left).toMatch('50%');

const trackStyle = wrapper.find('.rc-slider-track > .rc-slider-track').at(0).props().style;
expect(trackStyle.left).toMatch('0%');
expect(trackStyle.width).toMatch('50%');
const trackStyle0 = wrapper.find('.rc-slider-track > .rc-slider-track').at(0).props().style;
expect(trackStyle0.left).toMatch('0%');
expect(trackStyle0.width).toMatch('0%');

const trackStyle1 = wrapper.find('.rc-slider-track > .rc-slider-track').at(1).props().style;
expect(trackStyle1.left).toMatch('0%');
expect(trackStyle1.width).toMatch('50%');
});

it('should render Range with tabIndex correctly', () => {
Expand Down Expand Up @@ -66,15 +70,19 @@ describe('Range', () => {
expect(wrapper.find('.rc-slider-handle > .rc-slider-handle').at(2).props().style.left).toMatch('50%');
expect(wrapper.find('.rc-slider-handle > .rc-slider-handle').at(3).props().style.left).toMatch('75%');

const track1Style = wrapper.find('.rc-slider-track > .rc-slider-track').at(0).props().style;
const track0Style = wrapper.find('.rc-slider-track > .rc-slider-track').at(0).props().style;
expect(track0Style.left).toMatch('0%');
expect(track0Style.width).toMatch('0%');

const track1Style = wrapper.find('.rc-slider-track > .rc-slider-track').at(1).props().style;
expect(track1Style.left).toMatch('0%');
expect(track1Style.width).toMatch('25%');

const track2Style = wrapper.find('.rc-slider-track > .rc-slider-track').at(1).props().style;
const track2Style = wrapper.find('.rc-slider-track > .rc-slider-track').at(2).props().style;
expect(track2Style.left).toMatch('25%');
expect(track2Style.width).toMatch('25%');

const track3Style = wrapper.find('.rc-slider-track > .rc-slider-track').at(2).props().style;
const track3Style = wrapper.find('.rc-slider-track > .rc-slider-track').at(3).props().style;
expect(track3Style.left).toMatch('50%');
expect(track3Style.width).toMatch('25%');
});
Expand Down
8 changes: 8 additions & 0 deletions tests/__snapshots__/Range.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ exports[`Range should render Multi-Range with correct DOM structure 1`] = `
<div
class="rc-slider-rail"
/>
<div
class="rc-slider-track rc-slider-track-0"
style="left:0%;width:0%"
/>
<div
class="rc-slider-track rc-slider-track-1"
style="left:0%;width:0%"
Expand Down Expand Up @@ -75,6 +79,10 @@ exports[`Range should render Range with correct DOM structure 1`] = `
<div
class="rc-slider-rail"
/>
<div
class="rc-slider-track rc-slider-track-0"
style="left:0%;width:0%"
/>
<div
class="rc-slider-track rc-slider-track-1"
style="left:0%;width:0%"
Expand Down