/
Select.mjs
50 lines (40 loc) · 1.47 KB
/
Select.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
import classNameProp from "class-name-prop";
import React from "react";
import useCustomValidity from "./useCustomValidity.mjs";
import useMergedRef from "./useMergedRef.mjs";
import useOnFocusReportValidity from "./useOnFocusReportValidity.mjs";
/** CSS dependency URLs for the React component {@linkcode Select}. */
export const css = new Set([new URL("./Select.css", import.meta.url).href]);
/** React component for an input that provides a selection of options. */
const Select = React.forwardRef(
(
/**
* @type {SelectProps
* & React.ComponentPropsWithoutRef<"select">
* & { [dataAttribute: `data-${string}`]: unknown }}
*/
{ validationMessage, className, ...props },
/** @type {React.ForwardedRef<HTMLSelectElement>} */
ref
) => {
const selectRef = useMergedRef([ref]);
useCustomValidity(selectRef, validationMessage);
useOnFocusReportValidity(selectRef);
return React.createElement("select", {
className: classNameProp("daui-Select", className),
...props,
ref: selectRef,
});
}
);
Select.displayName = "Select";
export default Select;
/**
* Props for the {@linkcode Select} React component, excluding additional props
* for the {@linkcode HTMLSelectElement}.
* @typedef {object} SelectProps
* @prop {string} [validationMessage] Sets the
* [`validationMessage`](https://html.spec.whatwg.org/dev/form-control-infrastructure.html#dom-cva-validationmessage).
* Defaults to `""`.
*/