feat(Segments): 添加只读属性并优化相关交互

- 在 Segments 组件中添加 readonly 属性
- 实现只读状态下的组件行为
- 为选项添加 aria-readonly 属性
- 调整只读状态下选项的样式
This commit is contained in:
Vixalie
2025-08-24 11:27:11 +08:00
parent df1ccb783f
commit 21426a27b2

View File

@@ -24,6 +24,7 @@ interface SegmentsProps {
defaultValue?: Option['value'];
direction?: 'horizontal' | 'vertical';
disabled?: boolean;
readonly?: boolean;
onChange?: (value: Option['value'] | undefined) => void;
}
@@ -32,6 +33,7 @@ const Segments: Component<SegmentsProps> = (props) => {
{
options: [],
disabled: false,
readonly: false,
direction: 'horizontal',
},
props,
@@ -69,7 +71,7 @@ const Segments: Component<SegmentsProps> = (props) => {
});
const handleSelect = (value: Option['value']) => {
if (mProps.disabled) {
if (mProps.disabled || mProps.readonly) {
return;
}
setSelected(value);
@@ -88,8 +90,9 @@ const Segments: Component<SegmentsProps> = (props) => {
<div
ref={(el) => (optionRefs[index] = el)}
aria-disabled={mProps.disabled}
aria-readonly={mProps.readonly}
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
? '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',