返回介绍

Ionic4 搜索框组件 ion-searchbar

发布于 2019-11-22 18:04:18 字数 10433 浏览 1596 评论 0 收藏 0

Ionic4项目中我们可以使用Ionic4搜索框组件ion-searchbar对项目进行布局。

ion-searchbar官方文档地址:https://ionicframework.com/docs/api/searchbar

Searchbars represent a text field that can be used to search through a collection. They can be displayed inside of a toolbar or the main content.

A Searchbar should be used instead of an input to search lists. A clear button is displayed upon entering input in the searchbar's text field. Clicking on the clear button will erase the text field and the input will remain focused. A cancel button can be enabled which will clear the input and lose the focus upon click.

ion-searchbar 用法(Usage)






























  
</ion-toolbar>





























  
</ion-toolbar>
import React from 'react';

import { IonSearchbar, IonToolbar } from '@ionic/react';

const Example: React.SFC = () => (
  
    {/*-- Default Searchbar --*/}
    

    {/*-- Searchbar with danger color --*/}
    

    {/*-- Searchbar with value --*/}
    

    {/*-- Searchbar with telephone type --*/}
    

    {/*-- Searchbar disabled  --*/}
    

    {/*-- Searchbar with a cancel button and custom cancel button text --*/}
    

    {/*-- Searchbar with a custom debounce --*/}
    

    {/*-- Animated Searchbar --*/}
    

    {/*-- Searchbar with a placeholder --*/}
    

    {/*-- Searchbar in a Toolbar --*/}
    
      
    
  
);

export default Example;

  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  
    
  
</template>

ion-searchbar 属性(Properties)

animated

Description

If true, enable searchbar animation.

Attributeanimated
Typeboolean
Defaultfalse

autocomplete

Description

Set the input's autocomplete property.

Attributeautocomplete
Type"off" | "on"
Default'off'

autocorrect

Description

Set the input's autocorrect property.

Attributeautocorrect
Type"off" | "on"
Default'off'

cancelButtonIcon

Description

Set the cancel button icon. Only applies to md mode.

Attributecancel-button-icon
Typestring
Default'md-arrow-back'

cancelButtonText

Description

Set the the cancel button text. Only applies to ios mode.

Attributecancel-button-text
Typestring
Default'Cancel'

clearIcon

Description

Set the clear icon. Defaults to "close-circle" for ios and "close" for md.

Attributeclear-icon
Typestring | undefined

color

Description

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.

Attributecolor
Typestring | undefined

debounce

Description

Set the amount of time, in milliseconds, to wait to trigger the ionChange event after each keystroke.

Attributedebounce
Typenumber
Default250

disabled

Description

If true, the user cannot interact with the input.

Attributedisabled
Typeboolean
Defaultfalse

mode

Description

The mode determines which platform styles to use.

Attributemode
Type"ios" | "md"

placeholder

Description

Set the input's placeholder. placeholder can accept either plaintext or HTML as a string. To display characters normally reserved for HTML, they must be escaped. For example <Ionic> would become <Ionic>

For more information: Security Documentation

Attributeplaceholder
Typestring
Default'Search'

searchIcon

Description

The icon to use as the search icon.

Attributesearch-icon
Typestring
Default'search'

showCancelButton

Description

If true, show the cancel button.

Attributeshow-cancel-button
Typeboolean
Defaultfalse

spellcheck

Description

If true, enable spellcheck on the input.

Attributespellcheck
Typeboolean
Defaultfalse

type

Description

Set the type of the input.

Attributetype
Type"email" | "number" | "password" | "search" | "tel" | "text" | "url"
Default'search'

value

Description

the value of the searchbar.

Attributevalue
Typenull | string | undefined
Default''

ion-searchbar 事件(Events)

NameDescription
ionBlurEmitted when the input loses focus.
ionCancelEmitted when the cancel button is clicked.
ionChangeEmitted when the value has changed.
ionClearEmitted when the clear input button is clicked.
ionFocusEmitted when the input has focus.
ionInputEmitted when a keyboard input ocurred.

ion-searchbar 内置方法(Methods)

getInputElement

Description

Returns the native <input> element used under the hood.

SignaturegetInputElement() => Promise<HTMLInputElement>

setFocus

Description

Sets focus on the specified ion-searchbar. Use this method instead of the global input.focus().

SignaturesetFocus() => void

ion-searchbar中的CSS 自定义属性

NameDescription
--backgroundBackground of the searchbar
--cancel-button-colorColor of the searchbar cancel button
--clear-button-colorColor of the searchbar clear button
--colorColor of the searchbar text
--icon-colorColor of the searchbar icon
--placeholder-colorColor of the searchbar placeholder
--placeholder-font-styleFont style of the searchbar placeholder
--placeholder-font-weightFont weight of the searchbar placeholder
--placeholder-opacityOpacity of the searchbar placeholder

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文