feat(components): 添加默认选中功能
- 在 Check、Radio、RadioGroup 和 Segments 组件中添加默认选中值属性 - 使用 onMount 在组件挂载时设置默认选中值 - 优化了组件的初始化逻辑,确保默认值能够正确显示
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
Index,
|
||||
JSX,
|
||||
mergeProps,
|
||||
onMount,
|
||||
Show,
|
||||
} from 'solid-js';
|
||||
|
||||
@@ -20,6 +21,7 @@ interface SegmentsProps {
|
||||
name?: string;
|
||||
options: Option[];
|
||||
value?: Option['value'];
|
||||
defaultValue?: Option['value'];
|
||||
direction?: 'horizontal' | 'vertical';
|
||||
disabled?: boolean;
|
||||
onChange?: (value: Option['value'] | undefined) => void;
|
||||
@@ -43,6 +45,11 @@ const Segments: Component<SegmentsProps> = (props) => {
|
||||
const [indicatorHeight, setIndicatorHeight] = createSignal(0);
|
||||
const [indicatorWidth, setIndicatorWidth] = createSignal(0);
|
||||
|
||||
onMount(() => {
|
||||
if (isNotNil(mProps.defaultValue)) {
|
||||
setSelected(mProps.defaultValue);
|
||||
}
|
||||
});
|
||||
createEffect(() => {
|
||||
if (isNotNil(originalValue()) && originalValue() !== selected()) {
|
||||
setSelected(originalValue());
|
||||
|
Reference in New Issue
Block a user