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

[LinearProgress] Use transform instead width #7732

Merged
merged 1 commit into from
Aug 11, 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
20 changes: 11 additions & 9 deletions src/Progress/LinearProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ export const styleSheet = createStyleSheet('MuiLinearProgress', theme => ({
backgroundPosition: '0px -23px',
},
bar: {
width: '100%',
position: 'absolute',
left: 0,
bottom: 0,
top: 0,
transition: 'transform 0.2s linear',
transformOrigin: 'left',
},
dashed: {
position: 'absolute',
Expand All @@ -53,7 +55,7 @@ export const styleSheet = createStyleSheet('MuiLinearProgress', theme => ({
animation: 'buffer 3s infinite linear',
},
bufferBar2: {
transition: `width .${transitionDuration}s linear`,
transition: `transform .${transitionDuration}s linear`,
},
rootBuffer: {
backgroundColor: 'transparent',
Expand All @@ -71,19 +73,19 @@ export const styleSheet = createStyleSheet('MuiLinearProgress', theme => ({
animationDelay: '1.15s',
},
determinateBar1: {
willChange: 'width',
transition: `width .${transitionDuration}s linear`,
willChange: 'transform',
transition: `transform .${transitionDuration}s linear`,
},
bufferBar1: {
zIndex: 1,
transition: `width .${transitionDuration}s linear`,
transition: `transform .${transitionDuration}s linear`,
},
bufferBar2Primary: {
transition: `width .${transitionDuration}s linear`,
transition: `transform .${transitionDuration}s linear`,
backgroundColor: theme.palette.primary[100],
},
bufferBar2Accent: {
transition: `width .${transitionDuration}s linear`,
transition: `transform .${transitionDuration}s linear`,
backgroundColor: theme.palette.accent.A100,
},
'@keyframes mui-indeterminate1': {
Expand Down Expand Up @@ -167,11 +169,11 @@ function LinearProgress(props) {
const rootProps = {};

if (mode === 'determinate') {
styles.primary.width = `${value}%`;
styles.primary.transform = `scaleX(${value / 100})`;
rootProps['aria-valuenow'] = Math.round(value);
} else if (mode === 'buffer') {
styles.primary.width = `${value}%`;
styles.secondary.width = `${valueBuffer}%`;
styles.primary.transform = `scaleX(${value / 100})`;
styles.secondary.transform = `scaleX(${valueBuffer / 100})`;
}

return (
Expand Down
18 changes: 15 additions & 3 deletions src/Progress/LinearProgress.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ describe('<LinearProgress />', () => {
it('should set width of bar1 on determinate mode', () => {
const wrapper = shallow(<LinearProgress mode="determinate" value={77} />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.childAt(0).props().style.width, '77%', 'should have width set');
assert.strictEqual(
wrapper.childAt(0).props().style.transform,
'scaleX(0.77)',
'should have width set',
);
assert.strictEqual(wrapper.props()['aria-valuenow'], 77);
});

Expand Down Expand Up @@ -226,8 +230,16 @@ describe('<LinearProgress />', () => {
it('should set width of bar1 and bar2 on buffer mode', () => {
const wrapper = shallow(<LinearProgress mode="buffer" value={77} valueBuffer={85} />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.childAt(1).props().style.width, '77%', 'should have width set');
assert.strictEqual(wrapper.childAt(2).props().style.width, '85%', 'should have width set');
assert.strictEqual(
wrapper.childAt(1).props().style.transform,
'scaleX(0.77)',
'should have width set',
);
assert.strictEqual(
wrapper.childAt(2).props().style.transform,
'scaleX(0.85)',
'should have width set',
);
});

it('should render with query classes', () => {
Expand Down