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

[Button] Fix styles classes isolation #13352

Merged
merged 3 commits into from
Oct 23, 2018
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
14 changes: 13 additions & 1 deletion packages/material-ui/src/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,31 @@ export const styles = theme => ({
},
/* Styles applied to the root element if `variant="outlined"` and `color="primary"`. */
outlinedPrimary: {
color: theme.palette.primary.main,
border: `1px solid ${fade(theme.palette.primary.main, 0.5)}`,
'&:hover': {
border: `1px solid ${theme.palette.primary.main}`,
backgroundColor: fade(theme.palette.primary.main, theme.palette.action.hoverOpacity),
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
'&$disabled': {
border: `1px solid ${theme.palette.action.disabled}`,
},
},
/* Styles applied to the root element if `variant="outlined"` and `color="secondary"`. */
outlinedSecondary: {
color: theme.palette.secondary.main,
border: `1px solid ${fade(theme.palette.secondary.main, 0.5)}`,
'&:hover': {
border: `1px solid ${theme.palette.secondary.main}`,
backgroundColor: fade(theme.palette.secondary.main, theme.palette.action.hoverOpacity),
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
'&$disabled': {
border: `1px solid ${theme.palette.action.disabled}`,
Expand Down Expand Up @@ -228,7 +240,7 @@ function Button(props) {

const fab = variant === 'fab' || variant === 'extendedFab';
const contained = variant === 'contained' || variant === 'raised';
const text = variant === 'text' || variant === 'flat' || variant === 'outlined';
eps1lon marked this conversation as resolved.
Show resolved Hide resolved
const text = variant === 'text' || variant === 'flat';
const className = classNames(
classes.root,
{
Expand Down
12 changes: 7 additions & 5 deletions packages/material-ui/src/Button/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ describe('<Button />', () => {
it('should render an outlined button', () => {
const wrapper = shallow(<Button variant="outlined">Hello World</Button>);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.text), true);
assert.strictEqual(wrapper.hasClass(classes.outlined), true);
assert.strictEqual(
wrapper.hasClass(classes.contained),
false,
'should not have the contained class',
);
assert.strictEqual(wrapper.hasClass(classes.text), false);
assert.strictEqual(wrapper.hasClass(classes.raised), false);
assert.strictEqual(wrapper.hasClass(classes.fab), false);
});
Expand All @@ -177,9 +177,10 @@ describe('<Button />', () => {
</Button>,
);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.text), true);
assert.strictEqual(wrapper.hasClass(classes.outlined), true);
assert.strictEqual(wrapper.hasClass(classes.textPrimary), true);
assert.strictEqual(wrapper.hasClass(classes.outlinedPrimary), true);
assert.strictEqual(wrapper.hasClass(classes.text), false);
assert.strictEqual(wrapper.hasClass(classes.textPrimary), false);
assert.strictEqual(wrapper.hasClass(classes.contained), false);
assert.strictEqual(wrapper.hasClass(classes.raised), false);
assert.strictEqual(wrapper.hasClass(classes.fab), false);
Expand All @@ -192,9 +193,10 @@ describe('<Button />', () => {
</Button>,
);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.text), true);
assert.strictEqual(wrapper.hasClass(classes.outlined), true);
assert.strictEqual(wrapper.hasClass(classes.textSecondary), true);
assert.strictEqual(wrapper.hasClass(classes.outlinedSecondary), true);
assert.strictEqual(wrapper.hasClass(classes.text), false);
assert.strictEqual(wrapper.hasClass(classes.textSecondary), false);
assert.strictEqual(wrapper.hasClass(classes.contained), false);
assert.strictEqual(wrapper.hasClass(classes.raised), false);
assert.strictEqual(wrapper.hasClass(classes.fab), false);
Expand Down