Duostrap Input
沿用经典 Duostrap 表单视觉风格的受控/非受控单行文本输入框。
Duostrap Input 将经典 forms.less 视觉样式(4px 圆角、内阴影、蓝色焦点光晕与 #eee 禁用/只读填充)应用于 Base Input,并在深色宿主中保持经典的归档浅色表单表面。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div
id="bs2-input-demo"
class="flex w-full max-w-md flex-col gap-4"
>
<div class="flex flex-col gap-1">
<div class="text-sm font-medium">Project name</div>
<proto-ui-duostrap-input-root></proto-ui-duostrap-input-root>
<div class="text-xs text-muted-foreground">
Shown in navigation headers and workspace links.
</div>
</div>
<div class="flex flex-col gap-1">
<div class="text-sm font-medium">Disabled</div>
<proto-ui-duostrap-input-root></proto-ui-duostrap-input-root>
</div>
<div class="flex flex-col gap-1">
<div class="text-sm font-medium">Read only</div>
<proto-ui-duostrap-input-root></proto-ui-duostrap-input-root>
</div>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const props = [
{
defaultValue: 'Proto UI',
placeholder: 'Name this project',
ariaLabel: 'Project name',
name: 'project-name',
maxLength: 80,
},
{
defaultValue: 'Archived workspace',
disabled: true,
ariaLabel: 'Disabled project name',
},
{
defaultValue: 'https://example.com/proto-ui',
readOnly: true,
inputMode: 'url',
ariaLabel: 'Read-only workspace URL',
},
];
document
.querySelectorAll(
'#bs2-input-demo proto-ui-duostrap-input-root'
)
.forEach((el, index) => {
setElementProps(el, props[index]);
});
</script>当前以工作区源码提供,将于 0.3.0-rc.1 及后续版本中提供;可从 @proto.ui/prototypes-duostrap/input 导入。查看已实现的子集。
import { DuostrapInputRoot } from '@/components/ui/duostrap-input';
export function Example() { return <DuostrapInputRoot placeholder="Type something..." ariaLabel="Basic input" />;}- 值与输入事件:支持受控
value与非受控defaultValue,统一处理输入、提交与 IME 组合事件。 - 只读与禁用:
readOnly保持可聚焦与文本选中,disabled阻止聚焦与编辑,两者均呈现经典的#eee背景与禁选光标。 - 表单字段组合:如需标签、帮助说明与红色校验反馈,请与 Duostrap
Field组合使用。
独立的基础 Duostrap 文本输入框。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-input-root
id="bs2-input-basic"
></proto-ui-duostrap-input-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#bs2-input-basic'), {
placeholder: 'Type something...',
ariaLabel: 'Basic input',
});
</script>搭配 Field、FieldLabel、FieldControl 与 FieldDescription 组合标准表单项。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-field-root id="bs2-input-field">
<proto-ui-duostrap-field-label>
Username
</proto-ui-duostrap-field-label>
<proto-ui-duostrap-field-control></proto-ui-duostrap-field-control>
<proto-ui-duostrap-field-description>
Choose a unique username for your account.
</proto-ui-duostrap-field-description>
</proto-ui-duostrap-field-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(
document.querySelector(
'#bs2-input-field proto-ui-duostrap-field-control'
),
{
placeholder: 'Enter your username',
autoComplete: 'username',
}
);
</script>通过 Field 的 invalid 与 errors 属性触发经典的 #953b39 红色错误边框与焦点光晕。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-field-root id="bs2-input-invalid">
<proto-ui-duostrap-field-label>
Input with error
</proto-ui-duostrap-field-label>
<proto-ui-duostrap-field-control></proto-ui-duostrap-field-control>
<proto-ui-duostrap-field-error>
Please correct the error.
</proto-ui-duostrap-field-error>
</proto-ui-duostrap-field-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#bs2-input-invalid');
setElementProps(root, {
invalid: true,
errors: ['Please correct the error.'],
});
setElementProps(
root.querySelector('proto-ui-duostrap-field-control'),
{
defaultValue: 'invalid-handle',
placeholder: 'Username',
}
);
</script>将输入框与 Duostrap Button 水平排列,构建经典的行内搜索条。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex w-full max-w-md items-start gap-2">
<proto-ui-duostrap-input-root
id="bs2-input-search"
></proto-ui-duostrap-input-root>
<proto-ui-duostrap-button>Search</proto-ui-duostrap-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#bs2-input-search'), {
placeholder: 'Search...',
inputMode: 'search',
enterKeyHint: 'search',
ariaLabel: 'Search',
});
</script>Root 属性
Section titled “Root 属性”| 属性 | 类型 | 默认值 |
|---|---|---|
value | string | undefined |
defaultValue | string | '' |
disabled | boolean | false |
readOnly | boolean | false |
placeholder | string | '' |
required | boolean | false |
name | string | '' |
autoComplete | string | '' |
minLength | number | -1 |
maxLength | number | -1 |
inputMode | 'none' 'text' 'tel' 'url' 'email' 'numeric' 'decimal' 'search' | undefined |
enterKeyHint | 'enter' 'done' 'go' 'next' 'previous' 'search' 'send' | undefined |
ariaLabel | string | '' |
labelledBy | string | '' |
describedBy | string | '' |
暴露状态、方法与事件
Section titled “暴露状态、方法与事件”- 状态:
value、disabled、readOnly、focused、focusVisible、composing - 方法:
focusSelf(options?)、blurSelf()、resetValue(value?: string): boolean - 事件:
valueChange、change、compositionStart、compositionUpdate、compositionEnd