20
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
// THE SOFTWARE.
22
22
23
- import React from 'react' ;
24
- import PropTypes from 'prop-types' ;
25
- import classnames from 'classnames' ;
23
+ import * as React from 'react' ;
24
+ import * as classnames from 'classnames' ;
25
+ // no mdc .d.ts file
26
+ // @ts -ignore
27
+ import { MDCSelectFoundation } from '@material/select/dist/mdc.select' ;
26
28
27
- export default class NativeControl extends React . Component {
28
- nativeControl_ = React . createRef ( ) ;
29
+ export interface NativeControlProps extends React . HTMLProps < HTMLSelectElement > {
30
+ className : string ;
31
+ disabled : boolean ;
32
+ foundation : MDCSelectFoundation ;
33
+ setRippleCenter : ( lineRippleCenter : number ) => void ;
34
+ handleDisabled : ( disabled : boolean ) => void ;
35
+ }
36
+
37
+ export default class NativeControl extends React . Component <
38
+ NativeControlProps ,
39
+ { }
40
+ > {
41
+ nativeControl_ : React . RefObject < HTMLSelectElement > = React . createRef ( ) ;
42
+
43
+ static defaultProps : NativeControlProps = {
44
+ className : '' ,
45
+ children : null ,
46
+ disabled : false ,
47
+ foundation : {
48
+ handleFocus : ( ) => { } ,
49
+ handleBlur : ( ) => { } ,
50
+ } ,
51
+ setRippleCenter : ( ) => { } ,
52
+ handleDisabled : ( ) => { } ,
53
+ } ;
29
54
30
- componentDidUpdate ( prevProps ) {
55
+
56
+ componentDidUpdate ( prevProps : NativeControlProps ) {
31
57
if ( this . props . disabled !== prevProps . disabled ) {
32
58
this . props . handleDisabled ( this . props . disabled ) ;
33
59
}
@@ -37,37 +63,37 @@ export default class NativeControl extends React.Component {
37
63
return classnames ( 'mdc-select__native-control' , this . props . className ) ;
38
64
}
39
65
40
- handleFocus = ( evt ) => {
66
+ handleFocus = ( evt : React . FocusEvent < HTMLSelectElement > ) => {
41
67
const { foundation, onFocus} = this . props ;
42
68
foundation . handleFocus ( evt ) ;
43
- onFocus ( evt ) ;
44
- }
69
+ onFocus && onFocus ( evt ) ;
70
+ } ;
45
71
46
- handleBlur = ( evt ) => {
72
+ handleBlur = ( evt : React . FocusEvent < HTMLSelectElement > ) => {
47
73
const { foundation, onBlur} = this . props ;
48
74
foundation . handleBlur ( evt ) ;
49
- onBlur ( evt ) ;
50
- }
75
+ onBlur && onBlur ( evt ) ;
76
+ } ;
51
77
52
- handleMouseDown = ( evt ) => {
78
+ handleMouseDown = ( evt : React . MouseEvent < HTMLSelectElement > ) => {
53
79
const { onMouseDown} = this . props ;
54
- this . setRippleCenter ( evt . clientX , evt . target ) ;
55
- onMouseDown ( evt ) ;
56
- }
80
+ this . setRippleCenter ( evt . clientX , evt . target as HTMLSelectElement ) ;
81
+ onMouseDown && onMouseDown ( evt ) ;
82
+ } ;
57
83
58
- handleTouchStart = ( evt ) => {
84
+ handleTouchStart = ( evt : React . TouchEvent < HTMLSelectElement > ) => {
59
85
const { onTouchStart} = this . props ;
60
86
const clientX = evt . touches [ 0 ] && evt . touches [ 0 ] . clientX ;
61
- this . setRippleCenter ( clientX , evt . target ) ;
62
- onTouchStart ( evt ) ;
63
- }
87
+ this . setRippleCenter ( clientX , evt . target as HTMLSelectElement ) ;
88
+ onTouchStart && onTouchStart ( evt ) ;
89
+ } ;
64
90
65
- setRippleCenter = ( xCoordinate , target ) => {
91
+ setRippleCenter = ( xCoordinate : number , target : HTMLSelectElement ) => {
66
92
if ( target !== this . nativeControl_ . current ) return ;
67
93
const targetClientRect = target . getBoundingClientRect ( ) ;
68
94
const normalizedX = xCoordinate - targetClientRect . left ;
69
95
this . props . setRippleCenter ( normalizedX ) ;
70
- }
96
+ } ;
71
97
72
98
render ( ) {
73
99
const {
@@ -104,44 +130,3 @@ export default class NativeControl extends React.Component {
104
130
) ;
105
131
}
106
132
}
107
-
108
- NativeControl . propTypes = {
109
- className : PropTypes . string ,
110
- children : PropTypes . node ,
111
- disabled : PropTypes . bool ,
112
- foundation : PropTypes . shape ( {
113
- handleFocus : PropTypes . func ,
114
- handleBlur : PropTypes . func ,
115
- } ) ,
116
- id : PropTypes . string ,
117
- onBlur : PropTypes . func ,
118
- onChange : PropTypes . func ,
119
- onFocus : PropTypes . func ,
120
- onTouchStart : PropTypes . func ,
121
- onMouseDown : PropTypes . func ,
122
- setRippleCenter : PropTypes . func ,
123
- handleDisabled : PropTypes . func ,
124
- value : PropTypes . oneOfType ( [
125
- PropTypes . string ,
126
- PropTypes . number ,
127
- ] ) ,
128
- } ;
129
-
130
- NativeControl . defaultProps = {
131
- className : '' ,
132
- children : null ,
133
- disabled : false ,
134
- foundation : {
135
- handleFocus : ( ) => { } ,
136
- handleBlur : ( ) => { } ,
137
- } ,
138
- id : null ,
139
- onBlur : ( ) => { } ,
140
- onChange : ( ) => { } ,
141
- onFocus : ( ) => { } ,
142
- onTouchStart : ( ) => { } ,
143
- onMouseDown : ( ) => { } ,
144
- setRippleCenter : ( ) => { } ,
145
- handleDisabled : ( ) => { } ,
146
- value : '' ,
147
- } ;
0 commit comments