-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
[SelectField] Fix TouchRipple effect when SelectField is disabled #6286
[SelectField] Fix TouchRipple effect when SelectField is disabled #6286
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we were misleading. The true issue seems to have nothing to do with disableTouchRipple
. I would avoid doing any changes on the property. But address the disabled forward to begin with.
src/DropDownMenu/DropDownMenu.js
Outdated
@@ -107,6 +107,10 @@ class DropDownMenu extends Component { | |||
*/ | |||
className: PropTypes.string, | |||
/** | |||
* If true, the icon element's ripple effect will be disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing dot at the end.
); | ||
assert.strictEqual(wrapper.find(TouchRipple).length, 0, 'should not contain a TouchRipple'); | ||
}); | ||
it('has a touchRipple effect if disableTouchRipple is undefined and disabled={false}', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We separate the tests with a blank line.
src/IconButton/IconButton.spec.js
Outdated
); | ||
assert.strictEqual(wrapper.find(TouchRipple).length, 1, 'should contain a TouchRipple descendent'); | ||
}); | ||
it('disables the ripple effect when disableTouchRipple={true}', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be better to use shorter description. We can always read the tests to have more details. What about disables the ripple effect
here. The comment applies to the other description.
src/SelectField/SelectField.spec.js
Outdated
import {mount} from 'enzyme'; | ||
import {assert} from 'chai'; | ||
import getMuiTheme from '../styles/getMuiTheme'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We avoid using blank line in the import list.
src/SelectField/SelectField.js
Outdated
@@ -36,6 +36,10 @@ class SelectField extends Component { | |||
*/ | |||
children: PropTypes.node, | |||
/** | |||
* If true, the icon element's ripple effect will be disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing dot at the end of the description.
@@ -31,6 +32,43 @@ describe('<DropDownMenu />', () => { | |||
}); | |||
}); | |||
|
|||
describe('prop: disabled', () => { | |||
it('disables the touchRipple effect if disableTouchRipple is undefined and disabled={true}', () => { | |||
const wrapper = mountWithContext( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we need to use the mount API. The shallow API should be enough for all the new tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I used mount is due to my testing strategy, as I had checked for the existence of a TouchRipple
component. There definitely has to be a better strategy though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's really around what you are trying to test. That's fair. We could have been testing that the right property is set, but I guess that an integration test is better suited here 👍 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you say that the unit tests for SelectField are extraneous? Because the behavior is dependent on DropDownMenu
src/DropDownMenu/DropDownMenu.js
Outdated
@@ -364,6 +370,7 @@ class DropDownMenu extends Component { | |||
{displayValue} | |||
</div> | |||
<IconButton | |||
disableTouchRipple={disableTouchRipple === undefined ? disabled : disableTouchRipple} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That logic can't be working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The passing tests are suggesting that the issue is coming from somewhere else. And true, from what I can see the true issue is that we don't forward the disabled
property to the IconButton.
That piece of logic is already inside the EnhancedButton
component. No need for duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So then, what I need to is to pass <DropDownMenu />
's disabled
prop to <IconButton />
, which would then disable the ripple effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed. Can you try that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure can
src/DropDownMenu/DropDownMenu.js
Outdated
@@ -364,6 +370,7 @@ class DropDownMenu extends Component { | |||
{displayValue} | |||
</div> | |||
<IconButton | |||
disableTouchRipple={disableTouchRipple === undefined ? disabled : disableTouchRipple} | |||
tabIndex={this.props.disabled ? -1 : undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we need that once we forward the disabled
property as it's already inside the EnhancedButton
component.
Ping @elazzabi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from my comments, it's good to be merged. Good work so far 👍 .
src/DropDownMenu/DropDownMenu.js
Outdated
@@ -176,6 +176,7 @@ class DropDownMenu extends Component { | |||
animated: true, | |||
autoWidth: true, | |||
disabled: false, | |||
disableKeyboardFocus: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this property for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I think that snuck in there. Definitely shouldn't be in there
src/DropDownMenu/DropDownMenu.js
Outdated
@@ -364,7 +365,8 @@ class DropDownMenu extends Component { | |||
{displayValue} | |||
</div> | |||
<IconButton | |||
tabIndex={this.props.disabled ? -1 : undefined} | |||
disabled={disabled} | |||
tabIndex={disabled ? -1 : undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EnhancedButton
already has a logic to implement that. I think that you can remove this line.
tabIndex: disabled || disableKeyboardFocus ? -1 : tabIndex,
@@ -31,6 +31,15 @@ describe('<DropDownMenu />', () => { | |||
}); | |||
}); | |||
|
|||
describe('prop: disabled', () => { | |||
it('disables the ripple effect', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('should forward the property', () => {
src/IconButton/IconButton.spec.js
Outdated
@@ -72,4 +77,12 @@ describe('<IconButton />', () => { | |||
assert.include(wrapper.props().style, hoveredStyle); | |||
}); | |||
}); | |||
describe('prop: disabled', () => { | |||
it('disables the ripple effect', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('should disable the ripple effect', () => {
src/IconButton/IconButton.spec.js
Outdated
describe('prop: disabled', () => { | ||
it('disables the ripple effect', () => { | ||
const wrapper = mountWithContext( | ||
<IconButton disabled={true} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add another test with disabled={false}
to makes sure (wrapper.find(TouchRipple).length === 1
?
import SelectField from './SelectField'; | ||
import TouchRipple from '../internal/TouchRipple'; | ||
|
||
describe('<SelectField />', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, it's increasing the coverage 👍 .
@Shahrukh-Zindani Use the squash and merge option next time. 16 commits in the git history is quite a mess. |
@solkaz Thanks 👍. |
Okay will be do that from now. |
@Shahrukh-Zindani Thanks, that's important from my point of view. |
@Shahrukh-Zindani Also, please don't merge something just because it has been accepted - in that case @oliviertassinari could have merged it himself. Instead, it gives an opportunity for final review. |
Closes #6278