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

fix(ripple): focus style alive when disabled #943

Merged
merged 4 commits into from Jun 21, 2019
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
6 changes: 6 additions & 0 deletions packages/ripple/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ export function withRipple<
}
}

componentDidUpdate(prevProps: P) {
if (this.props.disabled !== prevProps.disabled && this.props.disabled) {
this.foundation.handleBlur();
}
}

componentWillUnmount() {
if (this.foundation) {
this.isComponentMounted = false;
Expand Down
13 changes: 12 additions & 1 deletion test/unit/ripple/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {MDCRippleFoundation} from '@material/ripple/foundation';
import {MDCRippleAdapter} from '@material/ripple/adapter';
import {SpecificEventListener} from '@material/base/types';
import {mount} from 'enzyme';
import {withRipple, InjectedProps} from '../../../packages/ripple/index';

import Button from '../../../packages/button';
import {withRipple, InjectedProps} from '../../../packages/ripple';
Copy link

Choose a reason for hiding this comment

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

do you need this import here? It looks unused.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah this is just my habit.
I always separate node_module and local_module imports!
Does it look better to put it back??

Copy link
Author

Choose a reason for hiding this comment

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

Maybe I misunderstood your comment.
This code already existed before.
import {withRipple, InjectedProps} from '../../../packages/ripple';
I'm just moved it down.

Copy link

Choose a reason for hiding this comment

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

ah! Sorry I didn't notice that. Yes that was there before. Looks good.

import {createMockRaf} from '../helpers/raf';
import {coerceForTesting} from '../helpers/types';

Expand Down Expand Up @@ -480,3 +482,12 @@ test('unmounting component does not throw errors', (done) => {
done();
});
});

test('handleBlur is called when disabled is being true', () => {
const wrapper = mount(<Button />);
const foundation = coerceForTesting<RippledComponent>(wrapper.instance())
.foundation;
foundation.handleBlur = td.func<() => void>();
wrapper.setProps({disabled: true});
td.verify(foundation.handleBlur(), {times: 1});
});