@@ -16,7 +16,7 @@ export interface MdAutocompleteProps {
16
16
label ?: string | null ;
17
17
options : MdAutocompleteOptionProps [ ] ;
18
18
defaultOptions ?: MdAutocompleteOptionProps [ ] ;
19
- id ?: string | number | null | undefined ;
19
+ id ?: string ;
20
20
onChange ( e : MdAutocompleteOptionProps ) : void ;
21
21
name ?: string ;
22
22
value ?: string | number ;
@@ -35,7 +35,7 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
35
35
value,
36
36
options,
37
37
defaultOptions,
38
- id = null ,
38
+ id,
39
39
name,
40
40
placeholder = 'Søk' ,
41
41
disabled = false ,
@@ -53,7 +53,6 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
53
53
const [ autocompleteValue , setAutocompleteValue ] = useState ( '' ) ;
54
54
const [ results , setResults ] = useState < MdAutocompleteOptionProps [ ] > ( [ ] ) ;
55
55
56
- const uuid = id || uuidv4 ( ) ;
57
56
const inputId = id && id !== '' ? id : uuidv4 ( ) ;
58
57
59
58
const classNames = classnames ( 'md-autocomplete' , {
@@ -103,7 +102,7 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
103
102
return (
104
103
< div className = { classNames } >
105
104
< div className = "md-autocomplete__label" >
106
- < div > { label } </ div >
105
+ { label && label !== '' && < label htmlFor = { inputId } > { label } </ label > }
107
106
{ helpText && helpText !== '' && (
108
107
< div className = "md-autocomplete__help-button" >
109
108
< MdHelpButton
@@ -179,8 +178,8 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
179
178
: [ ]
180
179
) . map ( ( option ) => (
181
180
< button
182
- key = { `md-autocomplete-option-${ uuid } -${ option . value } ` }
183
- id = { `md-autocomplete-option-${ uuid } -${ option . value } ` }
181
+ key = { `md-autocomplete-option-${ inputId } -${ option . value } ` }
182
+ id = { `md-autocomplete-option-${ inputId } -${ option . value } ` }
184
183
type = "button"
185
184
tabIndex = { open ? 0 : - 1 }
186
185
className = { optionClass ( option ) }
0 commit comments