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

Commit 4d6bbc0

Browse files
guguMatt Goo
authored and
Matt Goo
committed
feat(radio): upgrade to typescript v1 (#777)
1 parent 4f523e3 commit 4d6bbc0

File tree

5 files changed

+56
-29
lines changed

5 files changed

+56
-29
lines changed

package-lock.json

Lines changed: 44 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"@material/list": "^1.0.0",
7979
"@material/menu-surface": "^1.0.1",
8080
"@material/notched-outline": "^0.41.0",
81-
"@material/radio": "^0.41.0",
81+
"@material/radio": "^1.1.0",
8282
"@material/ripple": "^1.0.0",
8383
"@material/select": "^0.40.1",
8484
"@material/snackbar": "^1.0.0",

packages/radio/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

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

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

112-
get adapter() {
112+
get adapter(): MDCRadioAdapter {
113113
return {
114114
addClass: (className: string) => {
115115
const classList = new Set(this.state.classList);

packages/radio/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@material/form-field": "^0.41.0",
20-
"@material/radio": "^0.41.0",
20+
"@material/radio": "^1.1.0",
2121
"@material/react-ripple": "^0.11.0",
2222
"classnames": "^2.2.6",
2323
"react": "^16.4.2"
@@ -26,3 +26,4 @@
2626
"access": "public"
2727
}
2828
}
29+

test/unit/radio/index.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as td from 'testdouble';
44
import {mount, shallow, ReactWrapper} from 'enzyme';
55
import {Radio, NativeRadioControl, RadioProps} from '../../../packages/radio/index';
66
import {coerceForTesting} from '../helpers/types';
7+
import {MDCRadioFoundation} from '@material/radio';
78

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

8586
test('calls foundation.setDisabled if child.props.disabled is true', () => {
86-
const setDisabled = td.func();
87+
const setDisabled = td.func<(disabled: boolean) => void>();
8788
const wrapper = mount<Radio>(
8889
<Radio>
8990
<NativeRadioControl disabled />
9091
</Radio>
9192
);
92-
wrapper.instance().foundation = {init: () => {}, setDisabled};
93+
wrapper.instance().foundation = {init: () => {}, setDisabled} as MDCRadioFoundation;
9394
wrapper.instance().componentDidMount();
9495
td.verify(setDisabled(true), {times: 1});
9596
});
@@ -134,7 +135,7 @@ test('renders label with for attribute tied to native control id', () => {
134135
test('calls foundation.setDisabled if children.props.disabled updates', () => {
135136
const wrapper = mount(<NativeControlUpdate />);
136137
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(
137-
wrapper.children()).instance().foundation.setDisabled = td.func();
138+
wrapper.children()).instance().foundation.setDisabled = td.func<(disabled: boolean) => null>();
138139
wrapper.setProps({disabled: true});
139140
td.verify(
140141
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(wrapper.children())
@@ -147,7 +148,7 @@ test('calls foundation.setDisabled if children.props.disabled updates', () => {
147148
test('calls foundation.setDisabled if children.props.disabled updates to false', () => {
148149
const wrapper = mount(<NativeControlUpdate disabled />);
149150
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(
150-
wrapper.children()).instance().foundation.setDisabled = td.func();
151+
wrapper.children()).instance().foundation.setDisabled = td.func<(disabled: boolean) => null>();
151152
wrapper.setProps({disabled: false});
152153
td.verify(
153154
coerceForTesting<ReactWrapper<RadioProps, {}, Radio>>(wrapper.children())
@@ -234,7 +235,7 @@ test('#componentWillUnmount destroys foundation', () => {
234235
</Radio>
235236
);
236237
const foundation = wrapper.instance().foundation;
237-
foundation.destroy = td.func();
238+
foundation.destroy = td.func<() => void>();
238239
wrapper.unmount();
239240
td.verify(foundation.destroy(), {times: 1});
240241
});

0 commit comments

Comments
 (0)