iter: c02 textField/textarea 补 disabled 禁用态(布尔或信号绑定)

This commit is contained in:
HIsheR
2026-10-23 16:10:32 +08:00
parent 2a5892a88c
commit f9324ddc6a
11 changed files with 52 additions and 16 deletions
+2 -2
View File
@@ -1,9 +1,9 @@
import { effect, h } from '@ui-arch/frame';
import type { TextFieldProps } from './types.js';
/*** 文本输入:value 信号双向绑定,onInput 为输入回调 ***/
/*** 文本输入:value 信号双向绑定,disabled 支持布尔或信号禁用,onInput 为输入回调 ***/
export function textField(props: TextFieldProps): HTMLInputElement {
const el = h('input', { class: 'ua-input', placeholder: props.placeholder ?? '' }) as HTMLInputElement;
const el = h('input', { class: 'ua-input', placeholder: props.placeholder ?? '', disabled: props.disabled }) as HTMLInputElement; // false/undefined 移除属性,Signal 走响应式
if (props.value) {
const signal = props.value;
el.addEventListener('input', () => signal(el.value)); // 用户输入写回信号
+2 -2
View File
@@ -1,9 +1,9 @@
import { effect, h } from '@ui-arch/frame';
import type { TextareaProps } from './types.js';
/*** 多行输入:value 信号双向绑定,onInput 为输入回调 ***/
/*** 多行输入:value 信号双向绑定,disabled 支持布尔或信号禁用,onInput 为输入回调 ***/
export function textarea(props: TextareaProps): HTMLTextAreaElement {
const el = h('textarea', { class: 'ua-textarea', rows: props.rows ?? 3, placeholder: props.placeholder ?? '' }) as HTMLTextAreaElement;
const el = h('textarea', { class: 'ua-textarea', rows: props.rows ?? 3, placeholder: props.placeholder ?? '', disabled: props.disabled }) as HTMLTextAreaElement; // false/undefined 移除属性,Signal 走响应式
if (props.value) {
const signal = props.value;
el.addEventListener('input', () => signal(el.value)); // 用户输入写回信号
+2
View File
@@ -20,6 +20,7 @@ export interface ButtonProps {
export interface TextFieldProps {
placeholder?: string; // 占位文案
value?: Signal<string>; // 双向绑定的信号
disabled?: boolean | Signal<boolean>; // 禁用态:布尔直接置位,传信号则动态同步
onInput?: (value: string) => void; // 输入回调
}
@@ -81,6 +82,7 @@ export interface TextareaProps {
placeholder?: string; // 占位文案
rows?: number; // 行数;缺省 3
value?: Signal<string>; // 双向绑定的信号
disabled?: boolean | Signal<boolean>; // 禁用态:布尔直接置位,传信号则动态同步
onInput?: (value: string) => void; // 输入回调
}
+12 -2
View File
@@ -14,8 +14,8 @@
"entry": "src/index.ts",
"exports": [
"button(props):按钮,variant = primary | ghost | danger,disabled 支持布尔或信号禁用",
"textField(props):文本输入,value 信号双向绑定",
"textarea(props):多行输入,value 信号双向绑定",
"textField(props):文本输入,value 信号双向绑定,disabled 支持布尔或信号禁用",
"textarea(props):多行输入,value 信号双向绑定,disabled 支持布尔或信号禁用",
"checkbox(props):复选框,checked 信号双向绑定,disabled 支持布尔或信号禁用",
"switchButton(props):开关,checked 信号双向绑定,disabled 支持布尔或信号禁用",
"select(props):自绘下拉选择(非原生 select),value 信号双向绑定,点外部 / Esc 关闭,选项弹层带微动画",
@@ -129,6 +129,11 @@
"t": "string",
"d": "占位文案"
},
{
"n": "disabled",
"t": "boolean | Signal<boolean>",
"d": "禁用态:布尔直接置位,传信号则动态同步"
},
{
"n": "onInput",
"t": "(value: string) => void",
@@ -164,6 +169,11 @@
"t": "string",
"d": "占位文案"
},
{
"n": "disabled",
"t": "boolean | Signal<boolean>",
"d": "禁用态:布尔直接置位,传信号则动态同步"
},
{
"n": "onInput",
"t": "(value: string) => void",
+3 -1
View File
@@ -776,7 +776,9 @@
/* —— 通用禁用态:置灰 + 禁用光标 —— */
.ua-btn:disabled,
.ua-checkbox:disabled,
.ua-switch-input:disabled {
.ua-switch-input:disabled,
.ua-input:disabled,
.ua-textarea:disabled {
opacity: 0.45;
cursor: not-allowed;
}