|
1 | 1 | import React, { useState, useContext, useRef } from 'react';
|
2 | 2 | import PropTypes from 'prop-types';
|
3 |
| -import { FormContext, handleInputChange, normalizeOptions } from './form-helpers'; |
| 3 | +import { FormContext, handleInputChange, normalizeOptions, handleOnInvalid } from './form-helpers'; |
4 | 4 | import { Dropdown } from '../mixed/Dropdown';
|
5 | 5 | import { useOpenState } from '../utils/useOpenState';
|
6 | 6 |
|
@@ -29,19 +29,7 @@ export function FormAutocomplete({
|
29 | 29 | const inputRef = useRef(null);
|
30 | 30 |
|
31 | 31 | return (
|
32 |
| - <Dropdown |
33 |
| - isOpen={isOpen()} |
34 |
| - items={normalizeOptions(options, FormData).filter(filter(searchValue))} |
35 |
| - onSelect={({ value, label }) => { |
36 |
| - formState.update(name, value); |
37 |
| - setSearchValue(label); |
38 |
| - close(); |
39 |
| - }} |
40 |
| - template={template} |
41 |
| - onTouchStart={() => setIgnoreBlur(true)} |
42 |
| - onMouseEnter={() => setIgnoreBlur(true)} |
43 |
| - onMouseLeave={() => setIgnoreBlur(false)} |
44 |
| - > |
| 32 | + <> |
45 | 33 | <input
|
46 | 34 | {...{ required, name, id, placeholder }}
|
47 | 35 | type="text"
|
@@ -72,13 +60,27 @@ export function FormAutocomplete({
|
72 | 60 | close();
|
73 | 61 | }
|
74 | 62 | }}
|
| 63 | + onInvalid={handleOnInvalid.bind(null, formState, name)} |
75 | 64 | value={searchValue}
|
76 | 65 | role="combobox"
|
77 | 66 | aria-autocomplete="list"
|
78 | 67 | aria-expanded="false"
|
79 | 68 | autoComplete="off"
|
80 | 69 | />
|
81 |
| - </Dropdown> |
| 70 | + <Dropdown |
| 71 | + isOpen={isOpen()} |
| 72 | + items={normalizeOptions(options, FormData).filter(filter(searchValue))} |
| 73 | + onSelect={({ value, label }) => { |
| 74 | + formState.update(name, value); |
| 75 | + setSearchValue(label); |
| 76 | + close(); |
| 77 | + }} |
| 78 | + template={template} |
| 79 | + onTouchStart={() => setIgnoreBlur(true)} |
| 80 | + onMouseEnter={() => setIgnoreBlur(true)} |
| 81 | + onMouseLeave={() => setIgnoreBlur(false)} |
| 82 | + /> |
| 83 | + </> |
82 | 84 | );
|
83 | 85 | }
|
84 | 86 |
|
|
0 commit comments