SuperAPI AI 工具集

sgds-components-input

前端与建站

查看项目

更新于 10-15 21:54

技能介绍

用途:<sgds-input> 是新加坡政府设计系统(SGDS)中的单行表单文本输入组件,用于承载标准 HTML 输入类型,并内置标签、提示文字、校验反馈、前缀/后缀、加载状态和 action 插槽。当用户需要构建文本输入表单控件时使用本技能。

主要能力:支持 text、email、number、tel、password、search、date、time、url、datetime-local、month、week、color 等输入类型;支持 label 标签、hintText 提示、prefix 前缀与 suffix 后缀文本、placeholder 占位符,以及 minlength、maxlength、min、max、step、pattern 等约束属性。校验方面,通过 hasFeedback 控制反馈方式(style 仅边框颜色、text 仅消息、both 边框加消息),并需同时设置 invalidFeedback 错误信息;也可用 invalid、valid 手动设定状态。required、disabled、readonly、autofocus、noValidate 控制表单行为,loading 在输入框内显示加载指示器。

使用方式:以标签形式书写,如 <sgds-input type="text" label="Full Name" hintText="Enter your full name as per NRIC" name="fullName" required></sgds-input>。文本形式的前缀/后缀直接内联在输入框边框中,例如 prefix="$" suffix=".00";若需要图标按钮,则改用 action 插槽,放入 <sgds-icon-button slot="action" variant="ghost" name="search"></sgds-icon-button>。事件包括 sgds-change(失焦或回车时提交值变化)、sgds-input(每次按键值变化)、sgds-focus、sgds-blur、sgds-invalid、sgds-valid;在响应式框架中,用 sgds-input 跟踪即时值,用 sgds-change 获取提交值。

适用场景:需要带标签与校验提示的文本、邮箱、数字、密码、搜索、日期时间等表单字段,以及带前缀后缀或图标操作按钮的输入框。

限制:安装与框架集成(React 19+、React ≤18、Vue、Angular)需参考 sgds-components-setup;该组件不暴露自定义属性和 CSS part,因此不支持 CSS 样式修改。使用 number 类型的 min/max 由原生约束数值边界。