FloatingSelect从功能上来说和RadioGroup是同一类组件. 但无论从视觉效果上还是易用性上都推荐使用FloatingSelect替代RadioGroup
与原生input类似, value属性是受控属性, defaultValue为非受控属性. onChange为回调属性, 接受激活 项的value作为参数.
FloatingSelect的data属性支持两种数据结构:
value和label相同时使用value和label不相同时使用import { FloatingSelect } from "@rtdui/core";
function ArrayOfStrings() {
return <FloatingSelect data={["React", "Angular", "Svelte", "Vue"]} />;
}
function ArrayOfObjects() {
return (
<FloatingSelect
data={[
{ value: "val1", label: "React" },
{ value: "val2", label: "Angular" },
{ value: "val3", label: "Svelte" },
{ value: "val4", label: "Vue" },
]}
/>
);
}
export default function Demo() {
const data = [
{
value: "preview",
label: (
<div className="flex items-center gap-0.5">
<IconEye size={16} />
<span>Preview</span>
</div>
),
},
{
value: "code",
label: (
<div className="flex items-center gap-0.5">
<IconCode size={16} />
<span>Code</span>
</div>
),
},
{
value: "export",
label: (
<div className="flex items-center gap-0.5">
<IconExternalLink size={16} />
<span>Export</span>
</div>
),
},
];
return <FloatingSelect data={data} />;
}| 属性名 | 类型 | 是否必须 | 默认值 | 说明 |
|---|---|---|---|---|
| color | string | undefined | no | Key of <code>theme.colors</code> or any valid CSS color, changes color of indicator, by default color is based on current color scheme | |
| data | (string | FloatingSelectItem)[] | yes | Data based on which controls are rendered | |
| defaultValue | string | undefined | no | Uncontrolled component default value | |
| disabled | boolean | undefined | no | Determines whether the component is disabled | |
| fullWidth | boolean | undefined | no | Determines whether the component should take 100% width of its parent, <code>false</code> by default | |
| name | string | undefined | no | Name of the radio group, by default random name is generated | |
| onChange | ((value: string) => void) | undefined | no | Called when value changes | |
| orientation | "horizontal" | "vertical" | undefined | no | "horizontal" | Determines in which orientation component id displayed |
| radius | "circle" | "xs" | "sm" | "md" | "lg" | undefined | no | "sm" | Key of <code>theme.radius</code> or any valid CSS value to set <code>border-radius</code>, numbers are converted to rem |
| readOnly | boolean | undefined | no | Determines whether the value can be changed | |
| size | "xs" | "sm" | "md" | "lg" | "xl" | undefined | no | "sm" | Controls <code>font-size</code>, <code>padding</code> and <code>height</code> properties |
| slots | { indicator?: string | undefined; } | undefined | no | ||
| transitionDuration | number | undefined | no | 200 | Indicator <code>transition-duration</code> in ms, set <code>0</code> to turn off transitions |
| value | string | undefined | no | Controlled component value | |
| withItemsSeparator | boolean | undefined | no | true | Determines whether there should be borders between items |