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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextField] Remove deprecated lifecycle method #629

Merged
merged 2 commits into from
Nov 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Enhancements

- `EventListener` no longer uses `componentWillUpdate` ([#628](https://github.com/Shopify/polaris-react/pull/628))
- `TextField` no longer uses `componentWillReceiveProps`([#628](https://github.com/Shopify/polaris-react/pull/628))
- EventListener`no longer uses`componentWillUpdate` ([#628](https://github.com/Shopify/polaris-react/pull/628))
- Allowed `Icon` to accept a React Node as a source ([#635](https://github.com/Shopify/polaris-react/pull/635)) (thanks to [@mbriggs](https://github.com/mbriggs) for the [original issue](https://github.com/Shopify/polaris-react/issues/449))

### Bug fixes
Expand Down
11 changes: 4 additions & 7 deletions src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export type Props = NonMutuallyExclusiveProps &
const getUniqueID = createUniqueIDFactory('TextField');

export default class TextField extends React.PureComponent<Props, State> {
static getDerivedStateFromProps(nextProps: Props, prevState: State) {
return {id: nextProps.id || prevState.id};
}

private input: HTMLElement;

constructor(props: Props) {
Expand All @@ -137,13 +141,6 @@ export default class TextField extends React.PureComponent<Props, State> {
}
}

// eslint-disable-next-line react/no-deprecated
componentWillReceiveProps(newProps: Props) {
this.setState((prevState) => ({
id: newProps.id || prevState.id,
}));
}

render() {
const {
id = this.state.id,
Expand Down
18 changes: 18 additions & 0 deletions src/components/TextField/tests/TextField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ describe('<TextField />', () => {
expect(typeof id).toBe('string');
expect(id).toBeTruthy();
});

it('updates with the new id from props', () => {
const id = 'input field';
const textField = mountWithAppProvider(
<TextField label="TextField" onChange={noop} />,
);
textField.setProps({id});
expect(textField.find('input').prop('id')).toBe(id);
});

it('updates with the previous id after the id prop has been removed', () => {
const id = 'input field';
const textField = mountWithAppProvider(
<TextField label="TextField" id={id} onChange={noop} />,
);
textField.setProps({});
expect(textField.find('input').prop('id')).toBe(id);
});
});

describe('autoComplete', () => {
Expand Down