TextInput

view
size
placeholder
label
note
validationState
errorMessage
errorPlacement
disabled
hasClear
import {TextInput} from '@gravity-ui/uikit';

TextInput 允许用户在用户界面中输入文本。

外观

TextInput 外观由 viewpin 属性控制。

查看

normal -的主视图 TextInput (默认使用)。

<TextInput placeholder="Placeholder" />

clear -可以与自定义包装器一起使用。 TextInput

<TextInput view="clear" placeholder="Placeholder" />

别针

允许你控制边框左右边缘 TextInput的视图。

<TextInput placeholder="Placeholder" pin="round-brick" />
<TextInput placeholder="Placeholder" pin="brick-brick" />
<TextInput placeholder="Placeholder" pin="brick-round" />

国家

已禁用

您不希望用户能够与组件交互的状态。 TextInput

<TextInput placeholder="Placeholder" disabled={true} />

错误

您要指明用户输入错误的状态。 TextInput要更改 TextInput 外观,请使用带有 "invalid" 值的 validationState 属性。可以通过该 errorMessage 属性添加可选的消息文本。默认情况下,消息文本在组件外部呈现。 可以使用该 errorPlacement 属性来更改此行为。

Error message
<TextInput placeholder="Placeholder" errorMessage="Error message" validationState="invalid" />
<TextInput placeholder="Placeholder" errorPlacement="inside" errorMessage="Error message" validationState="invalid" />

大小

s— 当标准控件过大(桌子、小牌)时使用。

m— 基本尺寸,用于大多数组件。

l— 在页面标题、模态窗口或弹出窗口中执行的基本控件。

xl— 用于促销和登陆页面。

<TextInput placeholder="Placeholder" size="s" />
<TextInput placeholder="Placeholder" size="m" />
<TextInput placeholder="Placeholder" size="l" />
<TextInput placeholder="Placeholder" size="xl" />

标签

允许您将标签设置在控件的左侧。

  • 标签占据相对于控件的最左侧位置。也就是说,通过 startContent 属性添加的元素将位于右侧。
  • 标签占用的宽度不能超过整个 TextInput 空间宽度的一半。
<TextInput placeholder="Placeholder" label="Label" />
<TextInput placeholder="Placeholder" label="Very long label with huge amount of symbols" />

其他内容

开始内容

允许您在控件的左侧(如果使用 rtl,则向右添加内容)。位于通过 label 属性添加的标签的左侧(如果使用 rtl,则位于右侧)。

Left
<TextInput placeholder="Placeholder" label="Label" startContent={<Label size="s">Left</Label>} />

结束内容

允许您在控件的右侧(如果使用 rtl ,则向左添加内容)。位于通过 hasClear 属性添加的清除按钮的右侧(如果使用 rtl,则位于左侧)。

Right
<TextInput placeholder="Placeholder" endContent={<Label size="s">Right</Label>} hasClear/>

属性

姓名描述类型默认
autoComplete控件的 autocomplete 属性boolean string
autoFocus控件的 autofocus 属性boolean
className控件的包装器类名string
controlProps控件的 html 属性react.inputhtmlAtributes<HTMLInputElement>
controlRef向控件提供了 React refReact.Ref<HTMLInputElement>
defaultValue控件的默认值,在组件不受控制时使用string
残疾的表示用户无法与控件进行交互React.ReactNode
endContent在输入节`点、清除按钮和错误图标之后呈现的用户节点string
errorMessage错误文本string
errorPlacement放置错误outside insideoutside
hasClear显示用于清除控件值的图标booleanfalse
id控件的 id 属性string
标签在输入节点左侧呈现的帮助文本string
名称控件的 name 属性。如果未指定,则如果未指定,则自动生成string
便条显示在控件右下角的可选元素,与错误容器共享一个空间React.ReactNode
onBlur当控件失去对焦时触发。提供焦点事件作为回调的参数function
onChange当用户更改输入值时触发。提供变更事件作为回调的参数function
onFocus当控件获得焦点时触发。提供焦点事件作为回调的参数function
onKeyDown按下按键时触发。提供键盘事件作为回调的参数function
onKeyUp释放密钥时触发。提供键盘事件作为回调的参数function
onUpdate当用户更改输入值时触发。提供新值作为回调的参数function
大头针控件的边框视图string'round-round'
占位符未设置值时在控件中显示的文本string
qa测试 ID 属性 (data-qa)string
readOnly表示用户无法更改控件的值booleanfalse
尺寸控件的大小"s" "xl""m"
startContent在标签和输入节点之前呈现的用户`节点React.ReactNode
tabIndex控件的 tabindex 属性string
类型控件的类型"email" "url"
validationState验证状态"invalid"
价值控件的价值string
观点控件视图"normal" "clear""normal"

CSS API

姓名描述
--g-text-input-text-color文字颜色
--g-text-input-label-color标签颜色
--g-text-input-placeholder-color占位符颜色
--g-text-input-background-color背景颜色
--g-text-input-border-radius边框半径
--g-text-input-border-width边框宽度
--g-text-input-border-color边框颜色
--g-text-input-border-color-hover悬停时的边框颜色
--g-text-input-border-color-active边框颜色(如果处于活动状态)
--g-text-input-focus-outline-color聚焦时的轮廓颜色(默认情况下不显示)