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

[SelectField] Fix TouchRipple effect when SelectField is disabled #6286

Merged
merged 16 commits into from
Mar 6, 2017

Conversation

solkaz
Copy link
Contributor

@solkaz solkaz commented Mar 5, 2017

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

Closes #6278

@muibot muibot added PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Mar 5, 2017
Copy link
Member

@oliviertassinari oliviertassinari left a 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.

@@ -107,6 +107,10 @@ class DropDownMenu extends Component {
*/
className: PropTypes.string,
/**
* If true, the icon element's ripple effect will be disabled
Copy link
Member

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}', () => {
Copy link
Member

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.

);
assert.strictEqual(wrapper.find(TouchRipple).length, 1, 'should contain a TouchRipple descendent');
});
it('disables the ripple effect when disableTouchRipple={true}', () => {
Copy link
Member

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.

import {mount} from 'enzyme';
import {assert} from 'chai';
import getMuiTheme from '../styles/getMuiTheme';

Copy link
Member

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.

@@ -36,6 +36,10 @@ class SelectField extends Component {
*/
children: PropTypes.node,
/**
* If true, the icon element's ripple effect will be disabled
Copy link
Member

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(
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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 👍 .

Copy link
Contributor Author

@solkaz solkaz Mar 6, 2017

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

@@ -364,6 +370,7 @@ class DropDownMenu extends Component {
{displayValue}
</div>
<IconButton
disableTouchRipple={disableTouchRipple === undefined ? disabled : disableTouchRipple}
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure can

@@ -364,6 +370,7 @@ class DropDownMenu extends Component {
{displayValue}
</div>
<IconButton
disableTouchRipple={disableTouchRipple === undefined ? disabled : disableTouchRipple}
tabIndex={this.props.disabled ? -1 : undefined}
Copy link
Member

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.

@oliviertassinari oliviertassinari changed the title Fix ripple effect when SelectField is disabled [SelectField] Fix TouchRipple effect when SelectField is disabled Mar 5, 2017
@oliviertassinari oliviertassinari added the component: select This is the name of the generic UI component, not the React module! label Mar 5, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 5, 2017

Ping @elazzabi

Copy link
Member

@oliviertassinari oliviertassinari left a 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 👍 .

@@ -176,6 +176,7 @@ class DropDownMenu extends Component {
animated: true,
autoWidth: true,
disabled: false,
disableKeyboardFocus: false,
Copy link
Member

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?

Copy link
Contributor Author

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

@@ -364,7 +365,8 @@ class DropDownMenu extends Component {
{displayValue}
</div>
<IconButton
tabIndex={this.props.disabled ? -1 : undefined}
disabled={disabled}
tabIndex={disabled ? -1 : undefined}
Copy link
Member

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', () => {
Copy link
Member

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', () => {

@@ -72,4 +77,12 @@ describe('<IconButton />', () => {
assert.include(wrapper.props().style, hoveredStyle);
});
});
describe('prop: disabled', () => {
it('disables the ripple effect', () => {
Copy link
Member

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', () => {

describe('prop: disabled', () => {
it('disables the ripple effect', () => {
const wrapper = mountWithContext(
<IconButton disabled={true} />
Copy link
Member

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 />', () => {
Copy link
Member

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 👍 .

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work and removed PR: Needs Review labels Mar 6, 2017
@oliviertassinari oliviertassinari added PR: Review Accepted and removed PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 6, 2017
@Shahrukh-Zindani Shahrukh-Zindani merged commit e52628b into mui:master Mar 6, 2017
@oliviertassinari
Copy link
Member

@Shahrukh-Zindani Use the squash and merge option next time. 16 commits in the git history is quite a mess.

@solkaz solkaz deleted the select-field-disable-icon-ripple branch March 6, 2017 23:08
@oliviertassinari
Copy link
Member

@solkaz Thanks 👍.

@Shahrukh-Zindani
Copy link

Okay will be do that from now.

@oliviertassinari
Copy link
Member

@Shahrukh-Zindani Thanks, that's important from my point of view.

@mbrookes
Copy link
Member

mbrookes commented Mar 7, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: select This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants