|
|
@@ -8,10 +8,12 @@ export { FilterIcon, type FilterIconKind } from "./filter-icon";
|
|
|
type FilterSelectProps = Omit<SelectHTMLAttributes<HTMLSelectElement>, "value" | "defaultValue" | "multiple" | "size"> & {
|
|
|
icon: FilterIconKind;
|
|
|
value: string;
|
|
|
+ /** 显式声明当前是否停在占位项:默认项文案不是「全部…」开头时(如加载中的「载入出口…」)由调用方指定,⛔ 放宽下面的文字判断。 */
|
|
|
+ placeholder?: boolean;
|
|
|
};
|
|
|
|
|
|
/** 保留原生下拉交互,用当前选项的文本确定触发区宽度。 */
|
|
|
-export function FilterSelect({ icon, className, children, value, title, ...props }: FilterSelectProps) {
|
|
|
+export function FilterSelect({ icon, className, children, value, title, placeholder, ...props }: FilterSelectProps) {
|
|
|
const options = Children.toArray(children).flatMap((option) => {
|
|
|
if (!isValidElement<OptionHTMLAttributes<HTMLOptionElement>>(option) || option.type !== "option") return [];
|
|
|
const text = Children.toArray(option.props.children).join("").trim().replace(/\s+/g, " ");
|
|
|
@@ -21,8 +23,9 @@ export function FilterSelect({ icon, className, children, value, title, ...props
|
|
|
/**
|
|
|
* 占位态=停在「全部…」这一项(未选具体项):文字按占位样式显示,选了具体项恢复正文色。
|
|
|
* 按文字判断而不是按空值——多选筛选的「已选 N 个类型」取值同样为空,⛔ 当成占位。
|
|
|
+ * 调用方显式传 `placeholder` 时以它为准(默认项文案非「全部…」开头的场景)。
|
|
|
*/
|
|
|
- const placeholderSelected = selected != null && /^全部/.test(selected.label);
|
|
|
+ const placeholderSelected = placeholder ?? (selected != null && /^全部/.test(selected.label));
|
|
|
return <label className={cn("filter-select", className)} title={title ?? selected?.label}>
|
|
|
<FilterIcon kind={icon} />
|
|
|
<span className={cn("filter-select-value", placeholderSelected && "is-placeholder")} aria-hidden="true">{selected?.label}</span>
|