import React from "react"; import classNames from "classnames"; import { useTranslation } from "../i18n"; import { useDefaultValue } from "../form"; import { useConfig } from "../_util/config-context"; import { NativeSelectProps } from "./SelectProps"; import { SelectOptionWithGroup } from "./SelectOption"; function groupBy(options: SelectOptionWithGroup[]): SelectOptionWithGroup[][] { const groups = []; options.forEach((opt, index) => { const { groupKey } = opt; if (index === 0 || groupKey !== options[index - 1].groupKey) { groups.push([]); } groups[groups.length - 1].push(opt); }); return groups; } /** * 原生 Select */ export const NativeSelect = React.forwardRef(function NativeSelect( props: NativeSelectProps, ref: React.Ref ) { const t = useTranslation(); const { classPrefix } = useConfig(); const { type, value, onChange, options = [], groups = {}, placeholder = t.pleaseSelect, disabled, size, className, ...extraProps } = useDefaultValue(props, null); return ( ); }); NativeSelect.displayName = "NativeSelect";