Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

feat(radio): upgrade to typescript v1 #777

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
63 changes: 44 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@material/list": "^1.0.0",
"@material/menu-surface": "^0.41.0",
"@material/notched-outline": "^0.41.0",
"@material/radio": "^0.41.0",
"@material/radio": "^1.1.0",
"@material/ripple": "^1.0.0",
"@material/select": "^0.40.1",
"@material/snackbar": "^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/radio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import * as React from 'react';
import classnames from 'classnames';
// @ts-ignore no .d.ts file
import {MDCRadioFoundation} from '@material/radio/dist/mdc.radio';
import {MDCRadioFoundation} from '@material/radio/foundation';
import {MDCRadioAdapter} from '@material/radio/adapter';
import * as Ripple from '@material/react-ripple';
import NativeControl, {NativeControlProps} from './NativeControl'; // eslint-disable-line no-unused-vars

Expand Down Expand Up @@ -109,7 +109,7 @@ class Radio extends React.Component<RadioProps, RadioState> {
return classnames('mdc-radio', Array.from(classList), className);
}

get adapter() {
get adapter(): MDCRadioAdapter {
return {
addClass: (className: string) => {
const classList = new Set(this.state.classList);
Expand Down
3 changes: 2 additions & 1 deletion packages/radio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"@material/form-field": "^0.41.0",
"@material/radio": "^0.41.0",
"@material/radio": "^1.1.0",
"@material/react-ripple": "^0.11.0",
"classnames": "^2.2.6",
"react": "^16.4.2"
Expand All @@ -26,3 +26,4 @@
"access": "public"
}
}

11 changes: 6 additions & 5 deletions test/unit/radio/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as td from 'testdouble';
import {mount, shallow, ReactWrapper} from 'enzyme';
import {Radio, NativeRadioControl, RadioProps} from '../../../packages/radio/index';
import {coerceForTesting} from '../helpers/types';
import {MDCRadioFoundation} from '@material/radio';

const NativeControlUpdate: React.FunctionComponent<React.HTMLProps<HTMLInputElement>> = ({
disabled, id, // eslint-disable-line react/prop-types
Expand Down Expand Up @@ -83,13 +84,13 @@ test('initializes foundation', () => {
});

test('calls foundation.setDisabled if child.props.disabled is true', () => {
const setDisabled = td.func();
const setDisabled = td.func<(disabled: boolean) => void>();
const wrapper = mount<Radio>(
<Radio>
<NativeRadioControl disabled />
</Radio>
);
wrapper.instance().foundation = {init: () => {}, setDisabled};
wrapper.instance().foundation = {init: () => {}, setDisabled} as MDCRadioFoundation;
wrapper.instance().componentDidMount();
td.verify(setDisabled(true), {times: 1});
});
Expand Down Expand Up @@ -134,7 +135,7 @@ test('renders label with for attribute tied to native control id', () => {
test('calls foundation.setDisabled if children.props.disabled updates', () => {
const wrapper = mount(<NativeControlUpdate />);
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(
wrapper.children()).instance().foundation.setDisabled = td.func();
wrapper.children()).instance().foundation.setDisabled = td.func<(disabled: boolean) => null>();
wrapper.setProps({disabled: true});
td.verify(
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(wrapper.children())
Expand All @@ -147,7 +148,7 @@ test('calls foundation.setDisabled if children.props.disabled updates', () => {
test('calls foundation.setDisabled if children.props.disabled updates to false', () => {
const wrapper = mount(<NativeControlUpdate disabled />);
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(
wrapper.children()).instance().foundation.setDisabled = td.func();
wrapper.children()).instance().foundation.setDisabled = td.func<(disabled: boolean) => null>();
wrapper.setProps({disabled: false});
td.verify(
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(wrapper.children())
Expand Down Expand Up @@ -234,7 +235,7 @@ test('#componentWillUnmount destroys foundation', () => {
</Radio>
);
const foundation = wrapper.instance().foundation;
foundation.destroy = td.func();
foundation.destroy = td.func<() => void>();
wrapper.unmount();
td.verify(foundation.destroy(), {times: 1});
});