2020-10-07 14:49:01 +00:00
|
|
|
/**
|
|
|
|
* To match accessibility requirement, we always provide an input in the component.
|
|
|
|
* Other element will not set `tabIndex` to avoid `onBlur` sequence problem.
|
|
|
|
* For focused select, we set `aria-live="polite"` to update the accessibility content.
|
|
|
|
*
|
|
|
|
* ref:
|
|
|
|
* - keyboard: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role#Keyboard_interactions
|
|
|
|
*
|
|
|
|
* New api:
|
|
|
|
* - listHeight
|
|
|
|
* - listItemHeight
|
|
|
|
* - component
|
|
|
|
*
|
|
|
|
* Remove deprecated api:
|
|
|
|
* - multiple
|
|
|
|
* - tags
|
|
|
|
* - combobox
|
|
|
|
* - firstActiveValue
|
|
|
|
* - dropdownMenuStyle
|
|
|
|
* - openClassName (Not list in api)
|
|
|
|
*
|
|
|
|
* Update:
|
|
|
|
* - `backfill` only support `combobox` mode
|
|
|
|
* - `combobox` mode not support `labelInValue` since it's meaningless
|
|
|
|
* - `getInputElement` only support `combobox` mode
|
|
|
|
* - `onChange` return OptionData instead of ReactNode
|
|
|
|
* - `filterOption` `onChange` `onSelect` accept OptionData instead of ReactNode
|
|
|
|
* - `combobox` mode trigger `onChange` will get `undefined` if no `value` match in Option
|
|
|
|
* - `combobox` mode not support `optionLabelProp`
|
|
|
|
*/
|
|
|
|
|
2021-06-26 01:35:40 +00:00
|
|
|
import type { OptionsType as SelectOptionsType } from './interface';
|
2020-10-07 14:49:01 +00:00
|
|
|
import SelectOptionList from './OptionList';
|
|
|
|
import Option from './Option';
|
|
|
|
import OptGroup from './OptGroup';
|
|
|
|
import { convertChildrenToData as convertSelectChildrenToData } from './utils/legacyUtil';
|
|
|
|
import {
|
|
|
|
getLabeledValue as getSelectLabeledValue,
|
|
|
|
filterOptions as selectDefaultFilterOptions,
|
|
|
|
isValueDisabled as isSelectValueDisabled,
|
|
|
|
findValueOption as findSelectValueOption,
|
|
|
|
flattenOptions,
|
|
|
|
fillOptionsWithMissingValue,
|
|
|
|
} from './utils/valueUtil';
|
2021-06-26 01:35:40 +00:00
|
|
|
import type { SelectProps } from './generate';
|
2021-09-25 08:51:32 +00:00
|
|
|
import generateSelector, { selectBaseProps } from './generate';
|
2021-06-26 01:35:40 +00:00
|
|
|
import type { DefaultValueType } from './interface/generator';
|
2020-10-07 14:49:01 +00:00
|
|
|
import warningProps from './utils/warningPropsUtil';
|
|
|
|
import { defineComponent, ref } from 'vue';
|
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
const RefSelect = generateSelector<SelectOptionsType[number]>({
|
2020-10-07 14:49:01 +00:00
|
|
|
prefixCls: 'rc-select',
|
|
|
|
components: {
|
2020-10-28 07:31:45 +00:00
|
|
|
optionList: SelectOptionList as any,
|
2020-10-07 14:49:01 +00:00
|
|
|
},
|
|
|
|
convertChildrenToData: convertSelectChildrenToData,
|
|
|
|
flattenOptions,
|
|
|
|
getLabeledValue: getSelectLabeledValue,
|
|
|
|
filterOptions: selectDefaultFilterOptions,
|
|
|
|
isValueDisabled: isSelectValueDisabled,
|
|
|
|
findValueOption: findSelectValueOption,
|
|
|
|
warningProps,
|
|
|
|
fillOptionsWithMissingValue,
|
|
|
|
});
|
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
export type ExportedSelectProps<T extends DefaultValueType = DefaultValueType> = SelectProps<
|
|
|
|
SelectOptionsType[number],
|
|
|
|
T
|
|
|
|
>;
|
2020-10-07 14:49:01 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
export function selectProps<T>() {
|
|
|
|
return selectBaseProps<SelectOptionsType[number], T>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Select = defineComponent({
|
|
|
|
name: 'Select',
|
|
|
|
inheritAttrs: false,
|
|
|
|
Option,
|
|
|
|
OptGroup,
|
|
|
|
props: RefSelect.props,
|
2021-06-22 02:47:33 +00:00
|
|
|
setup(props, { attrs, expose, slots }) {
|
2021-09-25 08:51:32 +00:00
|
|
|
const selectRef = ref();
|
2021-06-22 02:47:33 +00:00
|
|
|
expose({
|
2020-10-07 14:49:01 +00:00
|
|
|
focus: () => {
|
|
|
|
selectRef.value?.focus();
|
|
|
|
},
|
|
|
|
blur: () => {
|
|
|
|
selectRef.value?.blur();
|
|
|
|
},
|
2021-06-22 02:47:33 +00:00
|
|
|
});
|
|
|
|
return () => {
|
|
|
|
return (
|
|
|
|
<RefSelect
|
|
|
|
ref={selectRef}
|
|
|
|
{...(props as any)}
|
|
|
|
{...attrs}
|
2021-08-11 07:22:49 +00:00
|
|
|
v-slots={slots}
|
2021-06-22 02:47:33 +00:00
|
|
|
children={slots.default?.() || []}
|
|
|
|
/>
|
|
|
|
);
|
2020-10-07 14:49:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
export default Select;
|