scoped
搜索栏代表一个文本字段,可用于搜索集合。它们可以显示在工具栏内部或主要内容中。搜索列表时应使用搜索栏而不是输入框。
搜索图标显示在搜索栏中输入字段的左侧。它可以自定义为任何 Ionicon。
当搜索栏有值或在搜索栏的文本字段中输入内容时,会显示一个清除按钮。点击清除按钮将擦除文本字段,并且输入框将保持焦点。默认情况下,清除按钮设置为在搜索栏获得焦点时显示,但可以设置为始终显示或从不显示。清除按钮内的图标也可以自定义为任何 Ionicon。
可以启用取消按钮,点击后会清除输入并失去焦点。默认情况下,取消按钮设置为从不显示,但可以设置为始终显示或仅在搜索栏获得焦点时显示。取消按钮在 ios 模式下显示为文本,在 md 模式下显示为图标。文本和图标都可以使用不同的属性进行自定义,图标可以接受任何 Ionicon。
搜索栏放置在工具栏内时,样式会呈现原生风格。在 iOS 中,搜索栏应放置在自己的工具栏中,位于包含页面标题的工具栏下方。在 Material Design 中,搜索栏要么持续显示在自己的工具栏中,要么展开覆盖包含页面标题的工具栏。
可以在搜索栏上设置防抖,以延迟触发 ionInput 事件。这在查询数据时非常有用,因为它可以用于等待发起请求,而不是每次在输入框中输入一个字符就请求数据。
搜索栏使用作用域封装,这意味着它会在运行时通过为每个样式附加一个额外的类来自动限定其 CSS 的作用域。在 CSS 中覆盖作用域选择器需要具有更高特异性的选择器。针对 ion-searchbar 进行自定义将不起作用,因此我们建议添加一个类并以这种方式进行自定义。
默认情况下,点击输入框会导致键盘出现,提交按钮上显示放大镜图标。你可以选择将 inputmode 属性设置为 "search",这会将图标从放大镜更改为回车键。
默认情况下,点击输入框会导致键盘出现,灰色提交按钮上显示文本"return"。你可以选择将 inputmode 属性设置为 "search",这会将文本从"return"更改为"go",并将按钮颜色从灰色更改为蓝色。或者,你可以将 ion-searchbar 包装在带有 action 属性的 form 元素中。这将导致键盘出现一个蓝色提交按钮,上面显示"search"。
interface SearchbarChangeEventDetail {
value?: string;
}
虽然不是必需的,但此接口可以替代 CustomEvent 接口,用于与此组件发出的 Ionic 事件提供更强的类型支持。
interface SearchbarCustomEvent extends CustomEvent {
detail: SearchbarChangeEventDetail;
target: HTMLIonSearchbarElement;
}
| 说明 | If true, enable searchbar animation. |
| 属性 | animated |
| 类型 | boolean |
| 默认值 | false |
| 说明 | Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. Available options: "off", "none", "on", "sentences", "words", "characters". |
| 属性 | autocapitalize |
| 类型 | string |
| 默认值 | 'off' |
| 说明 | Set the input's autocomplete property. |
| 属性 | autocomplete |
| 类型 | "additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday" | "bday-day" | "bday-month" | "bday-year" | "cc-additional-name" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "email" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "impp" | "language" | "name" | "new-password" | "nickname" | "off" | "on" | "one-time-code" | "organization" | "organization-title" | "photo" | "postal-code" | "sex" | "street-address" | "tel" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-national" | "transaction-amount" | "transaction-currency" | "url" | "username" |
| 默认值 | 'off' |
| 说明 | Set the input's autocorrect property. |
| 属性 | autocorrect |
| 类型 | "off" | "on" |
| 默认值 | 'off' |
| 说明 | Set the cancel button icon. Only applies to md mode. Defaults to arrow-back-sharp. |
| 属性 | cancel-button-icon |
| 类型 | string |
| 默认值 | config.get('backButtonIcon', arrowBackSharp) as string |
| 说明 | Set the cancel button text. Only applies to ios mode. |
| 属性 | cancel-button-text |
| 类型 | string |
| 默认值 | 'Cancel' |
| 说明 | Set the clear icon. Defaults to close-circle for ios and close-sharp for md. |
| 属性 | clear-icon |
| 类型 | string | undefined |
| 默认值 | undefined |
| 说明 | The color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming. |
| 属性 | color |
| 类型 | "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined |
| 默认值 | undefined |
| 说明 | Set the amount of time, in milliseconds, to wait to trigger the ionInput event after each keystroke. |
| 属性 | debounce |
| 类型 | number | undefined |
| 默认值 | undefined |
| 说明 | If true, the user cannot interact with the input. |
| 属性 | disabled |
| 类型 | boolean |
| 默认值 | false |
| 说明 | A hint to the browser for which enter key to display. Possible values: "enter", "done", "go", "next", "previous", "search", and "send". |
| 属性 | enterkeyhint |
| 类型 | "done" | "enter" | "go" | "next" | "previous" | "search" | "send" | undefined |
| 默认值 | undefined |
| 说明 | A hint to the browser for which keyboard to display. Possible values: "none", "text", "tel", "url", "email", "numeric", "decimal", and "search". |
| 属性 | inputmode |
| 类型 | "decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined |
| 默认值 | undefined |
| 说明 | This attribute specifies the maximum number of characters that the user can enter. |
| 属性 | maxlength |
| 类型 | number | undefined |
| 默认值 | undefined |