Skip to main content
Version: v7

ion-searchbar

scoped

検索バーは、コレクションを検索するために使用できるテキストフィールドを表します。ツールバーやメインコンテンツの中に表示することができます。検索バーは、検索リストへの入力の代わりに使用する必要があります。

基本的な使い方

検索アイコン

検索バーのInputフィールドの左に表示される検索アイコンです。任意の Ionicon にカスタマイズすることが可能です。

クリアボタン

検索バーに値があるとき、または検索バーのテキストフィールドに入力があったときに、クリアボタンが表示されます。クリアボタンをクリックすると、テキストフィールドは消去され、入力はフォーカスされたままになります。デフォルトでは、クリアボタンは検索バーをフォーカスしたときに表示されるように設定されていますが、常に表示する、または全く表示しないように設定することができます。また、クリアボタン内のアイコンは、任意のIoniconにカスタマイズすることができます。

キャンセルボタン

キャンセルボタンを有効にすると、クリックすると入力がクリアされ、フォーカスが失われます。デフォルトでは、キャンセルボタンは表示されないように設定されていますが、常に表示するように設定したり、検索バーにフォーカスが当たったときのみ表示するように設定したりすることができます。キャンセルボタンは ios モードではテキストとして、md モードではアイコンとして表示されます。テキストとアイコンはそれぞれ別のプロパティでカスタマイズでき、アイコンは任意のIoniconを使用することができます。

ツールバーの中に配置した検索バー

検索バーは、ツールバーの中に配置されたときにネイティブに見えるようにスタイルされています。iOSでは、検索バーは、ページタイトルを含むツールバーの下にある、独自のツールバーに配置されるべきです。Material Designでは、検索バーは、独自のツールバーに永続的に表示されるか、ページタイトルを含むツールバーの上に展開されるかのいずれかです。

Debounce

検索バーにDebounceを設定して、ionChangeイベントのトリガーを遅延させることができます。これは、入力に文字が入力されるたびにデータを要求するのではなく、要求を出すのを待つために使うことができるので、データを問い合わせるときに便利です。

テーマ

Colors

CSSカスタムプロパティ

検索バーは、スコープをつけてカプセル化されています。これは、実行時に各スタイルに追加のクラスを付加することで、CSSを自動的にスコープ化することを意味します。CSSでscopedセレクタを上書きするには、higher specificity セレクタが必要です。そのため、クラスを追加してカスタマイズすることをお勧めします。

キーボード表示

Android

デフォルトでは、Inputをタップするとキーボードが表示され、サブミットボタンに虫眼鏡のアイコンが表示されます。オプションで inputmode プロパティを "search" に設定すると、アイコンが虫眼鏡からarriage returnに変更されます。

iOS

デフォルトでは、Inputをタップするとキーボードが表示され、グレーのSubmitボタンに「return」のテキストが表示されます。オプションで inputmode プロパティを "search" に設定すると、テキストが "return" から "go" に変わり、ボタンの色もグレーから青に変わります。また、ion-searchbarform 要素でラップして、 action プロパティを設定することもできます。これにより、キーボードが表示され、"search "という青いSubmitボタンが表示されるようになります。

Interfaces

SearchbarChangeEventDetail

interface SearchbarChangeEventDetail {
value?: string;
}

SearchbarCustomEvent

必須ではありませんが、このコンポーネントから発行される Ionic イベントでより強く型付けを行うために、CustomEvent インターフェースの代わりにこのインターフェースを使用することが可能です。

interface SearchbarCustomEvent extends CustomEvent {
detail: SearchbarChangeEventDetail;
target: HTMLIonSearchbarElement;
}

プロパティ

animated

Descriptiontrueの場合、検索バーのアニメーションを有効にします。
Attributeanimated
Typeboolean
Defaultfalse

autocomplete

DescriptionInputのオートコンプリートプロパティを設定します。
Attributeautocomplete
Type"name" | "email" | "tel" | "url" | "on" | "off" | "honorific-prefix" | "given-name" | "additional-name" | "family-name" | "honorific-suffix" | "nickname" | "username" | "new-password" | "current-password" | "one-time-code" | "organization-title" | "organization" | "street-address" | "address-line1" | "address-line2" | "address-line3" | "address-level4" | "address-level3" | "address-level2" | "address-level1" | "country" | "country-name" | "postal-code" | "cc-name" | "cc-given-name" | "cc-additional-name" | "cc-family-name" | "cc-number" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-csc" | "cc-type" | "transaction-currency" | "transaction-amount" | "language" | "bday" | "bday-day" | "bday-month" | "bday-year" | "sex" | "tel-country-code" | "tel-national" | "tel-area-code" | "tel-local" | "tel-extension" | "impp" | "photo"
Default'off'

autocorrect

DescriptionInputのオートコレクトプロパティを設定します。
Attributeautocorrect
Type"off" | "on"
Default'off'

cancelButtonIcon

DescriptionSet the cancel button icon. Only applies to md mode. Defaults to arrow-back-sharp.
Attributecancel-button-icon
Typestring
Defaultconfig.get('backButtonIcon', arrowBackSharp) as string

cancelButtonText

Descriptionキャンセルボタンのテキストを設定します。 ios modeのみ適用されます。
Attributecancel-button-text
Typestring
Default'Cancel'

clearIcon

Descriptionクリアアイコンを設定します。デフォルトは ios の場合は close-circlemd の場合は close-sharp です。
Attributeclear-icon
Typestring | undefined
Defaultundefined

color

DescriptionThe 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
Type"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined
Defaultundefined

debounce

DescriptionSet the amount of time, in milliseconds, to wait to trigger the ionInput event after each keystroke.
Attributedebounce
Typenumber | undefined
Defaultundefined

disabled

Descriptiontrueの場合、ユーザはInputと対話することができません。
Attributedisabled
Typeboolean
Defaultfalse

enterkeyhint

DescriptionA hint to the browser for which enter key to display. Possible values: "enter", "done", "go", "next", "previous", "search", and "send".
Attributeenterkeyhint
Type"done" | "enter" | "go" | "next" | "previous" | "search" | "send" | undefined
Defaultundefined

inputmode

DescriptionA hint to the browser for which keyboard to display. Possible values: "none", "text", "tel", "url", "email", "numeric", "decimal", and "search".
Attributeinputmode
Type"decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined
Defaultundefined

mode

Descriptionmodeは、どのプラットフォームのスタイルを使用するかを決定します。
Attributemode
Type"ios" | "md"
Defaultundefined

name

DescriptionIf used in a form, set the name of the control, which is submitted with the form data.
Attributename
Typestring
Defaultthis.inputId

placeholder

DescriptionSet 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 &lt;Ionic&gt;

For more information: Security Documentation
Attributeplaceholder
Typestring
Default'Search'

searchIcon

DescriptionThe icon to use as the search icon. Defaults to search-outline in ios mode and search-sharp in md mode.
Attributesearch-icon
Typestring | undefined
Defaultundefined

showCancelButton

DescriptionSets the behavior for the cancel button. Defaults to "never". Setting to "focus" shows the cancel button on focus. Setting to "never" hides the cancel button. Setting to "always" shows the cancel button regardless of focus state.
Attributeshow-cancel-button
Type"always" | "focus" | "never"
Default'never'

showClearButton

DescriptionSets the behavior for the clear button. Defaults to "focus". Setting to "focus" shows the clear button on focus if the input is not empty. Setting to "never" hides the clear button. Setting to "always" shows the clear button regardless of focus state, but only if the input is not empty.
Attributeshow-clear-button
Type"always" | "focus" | "never"
Default'always'

spellcheck

Descriptiontrueの場合、入力値のスペルチェックを有効にします。
Attributespellcheck
Typeboolean
Defaultfalse

type

DescriptionInputの種類を設定します。
Attributetype
Type"email" | "number" | "password" | "search" | "tel" | "text" | "url"
Default'search'

value

Description検索バーの値。
Attributevalue
Typenull | string | undefined
Default''

イベント

NameDescription
ionBlurInputのフォーカスが外れたときに発行されます。
ionCancelキャンセルボタンがクリックされたときに発行されます。
ionChangeThe ionChange event is fired for <ion-searchbar> elements when the user modifies the element's value. Unlike the ionInput event, the ionChange event is not necessarily fired for each alteration to an element's value.

The ionChange event is fired when the value has been committed by the user. This can happen when the element loses focus or when the "Enter" key is pressed. ionChange can also fire when clicking the clear or cancel buttons.
ionClearClear Inputボタンがクリックされたときに発行されます。
ionFocusInputにフォーカスが当たったときに発行されます。
ionInputEmitted when the value of the ion-searchbar element has changed.

メソッド

getInputElement

Description要素の内部で使用されているネイティブの <input> 要素を返します。
SignaturegetInputElement() => Promise<HTMLInputElement>

setFocus

DescriptionSets focus on the native input in ion-searchbar. Use this method instead of the global input.focus().

Developers who wish to focus an input when a page enters should call setFocus() in the ionViewDidEnter() lifecycle method.

Developers who wish to focus an input when an overlay is presented should call setFocus after didPresent has resolved.
SignaturesetFocus() => Promise<void>

CSS Shadow Parts

No CSS shadow parts available for this component.

CSSカスタムプロパティ

NameDescription
--background検索バーのInputの背景
--border-radius検索バーのInputのボーダー半径
--box-shadow検索バーのInputのボックスシャドウ
--cancel-button-color検索バーのキャンセルボタンの色
--clear-button-color検索バーのクリアボタンの色
--color検索バーのテキストの色
--icon-color検索バーのアイコンの色
--placeholder-color検索バーのPlaceholderの色
--placeholder-font-style検索バーのPlaceholderのFont Style
--placeholder-font-weight検索バーのPlaceholderのFont Weight
--placeholder-opacity検索バーのPlaceholderの不透明度

Slots

No slots available for this component.