Skip to content

Commit d766b17

Browse files
fix: strange typing error only happening in build pipeline (#43)
* fix: strange typing error only happening in build pipeline * bump version * get inputId from props
1 parent 0f01cc7 commit d766b17

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@miljodirektoratet/md-react",
3-
"version": "1.0.28",
3+
"version": "1.0.29",
44
"description": "React-komponenter for Miljødirektoratet",
55
"author": "Miljødirektoratet",
66
"main": "./dist/index.js",

packages/react/src/formElements/MdAutocomplete.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface MdAutocompleteProps {
1616
label?: string | null;
1717
options: MdAutocompleteOptionProps[];
1818
defaultOptions?: MdAutocompleteOptionProps[];
19-
id?: string | number | null | undefined;
19+
id?: string;
2020
onChange(e: MdAutocompleteOptionProps): void;
2121
name?: string;
2222
value?: string | number;
@@ -35,7 +35,7 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
3535
value,
3636
options,
3737
defaultOptions,
38-
id = null,
38+
id,
3939
name,
4040
placeholder = 'Søk',
4141
disabled = false,
@@ -53,7 +53,6 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
5353
const [autocompleteValue, setAutocompleteValue] = useState('');
5454
const [results, setResults] = useState<MdAutocompleteOptionProps[]>([]);
5555

56-
const uuid = id || uuidv4();
5756
const inputId = id && id !== '' ? id : uuidv4();
5857

5958
const classNames = classnames('md-autocomplete', {
@@ -103,7 +102,7 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
103102
return (
104103
<div className={classNames}>
105104
<div className="md-autocomplete__label">
106-
<div>{label}</div>
105+
{label && label !== '' && <label htmlFor={inputId}>{label}</label>}
107106
{helpText && helpText !== '' && (
108107
<div className="md-autocomplete__help-button">
109108
<MdHelpButton
@@ -179,8 +178,8 @@ const MdAutocomplete: React.FunctionComponent<MdAutocompleteProps> = ({
179178
: []
180179
).map((option) => (
181180
<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}`}
184183
type="button"
185184
tabIndex={open ? 0 : -1}
186185
className={optionClass(option)}

0 commit comments

Comments
 (0)