feat(Segments): 添加只读属性并优化相关交互
- 在 Segments 组件中添加 readonly 属性 - 实现只读状态下的组件行为 - 为选项添加 aria-readonly 属性 - 调整只读状态下选项的样式
This commit is contained in:
@@ -24,6 +24,7 @@ interface SegmentsProps {
|
|||||||
defaultValue?: Option['value'];
|
defaultValue?: Option['value'];
|
||||||
direction?: 'horizontal' | 'vertical';
|
direction?: 'horizontal' | 'vertical';
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
readonly?: boolean;
|
||||||
onChange?: (value: Option['value'] | undefined) => void;
|
onChange?: (value: Option['value'] | undefined) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ const Segments: Component<SegmentsProps> = (props) => {
|
|||||||
{
|
{
|
||||||
options: [],
|
options: [],
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
readonly: false,
|
||||||
direction: 'horizontal',
|
direction: 'horizontal',
|
||||||
},
|
},
|
||||||
props,
|
props,
|
||||||
@@ -69,7 +71,7 @@ const Segments: Component<SegmentsProps> = (props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSelect = (value: Option['value']) => {
|
const handleSelect = (value: Option['value']) => {
|
||||||
if (mProps.disabled) {
|
if (mProps.disabled || mProps.readonly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSelected(value);
|
setSelected(value);
|
||||||
@@ -88,8 +90,9 @@ const Segments: Component<SegmentsProps> = (props) => {
|
|||||||
<div
|
<div
|
||||||
ref={(el) => (optionRefs[index] = el)}
|
ref={(el) => (optionRefs[index] = el)}
|
||||||
aria-disabled={mProps.disabled}
|
aria-disabled={mProps.disabled}
|
||||||
|
aria-readonly={mProps.readonly}
|
||||||
class={cx(
|
class={cx(
|
||||||
'z-[5] cursor-pointer rounded-sm px-2 py-0.5',
|
'z-[5] cursor-pointer rounded-sm px-2 py-0.5 aria-readonly:cursor-not-allowed',
|
||||||
selected() === option().value
|
selected() === option().value
|
||||||
? 'not-aria-disabled:text-on-primary-surface aria-disabled:text-primary-disabled'
|
? 'not-aria-disabled:text-on-primary-surface aria-disabled:text-primary-disabled'
|
||||||
: 'not-aria-disabled:text-on-surface aria-disabled:text-neutral-disabled hover:not-aria-disabled:text-primary-hover',
|
: 'not-aria-disabled:text-on-surface aria-disabled:text-neutral-disabled hover:not-aria-disabled:text-primary-hover',
|
||||||
|
Reference in New Issue
Block a user