ion-searchbar
컬렉션을 검색하는 데 사용할 수 있는 텍스트 필드를 나타내는 컴포넌트예요. 툴바 안이나 메인 콘텐츠에 표시할 수 있으며, 목록을 검색할 때는 input 대신 searchbar를 사용해야 합니다.
출처: 문서
본문
Encapsulation: scoped
Searchbar는 컬렉션을 검색하는 데 사용할 수 있는 텍스트 필드를 나타내요. 툴바 안이나 메인 콘텐츠에 표시할 수 있습니다. 목록을 검색할 때는 input 대신 searchbar를 사용해야 해요.
Basic Usage
JavaScript
<ion-searchbar></ion-searchbar>
<ion-searchbar placeholder="Custom Placeholder"></ion-searchbar>
<ion-searchbar disabled="true" placeholder="Disabled"></ion-searchbar>
<ion-searchbar value="Value"></ion-searchbar>
<ion-searchbar animated="true" placeholder="Animated"></ion-searchbar>
Angular
src/app/example.component.html
<ion-searchbar></ion-searchbar>
<ion-searchbar placeholder="Custom Placeholder"></ion-searchbar>
<ion-searchbar disabled="true" placeholder="Disabled"></ion-searchbar>
<ion-searchbar value="Value"></ion-searchbar>
<ion-searchbar animated="true" placeholder="Animated"></ion-searchbar>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonSearchbar],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonSearchbar } from '@ionic/react';
function Example() {
return (
<>
<IonSearchbar></IonSearchbar>
<IonSearchbar placeholder="Custom Placeholder"></IonSearchbar>
<IonSearchbar disabled={true} placeholder="Disabled"></IonSearchbar>
<IonSearchbar value="Value"></IonSearchbar>
<IonSearchbar animated={true} placeholder="Animated"></IonSearchbar>
</>
);
}
export default Example;
Vue
<template>
<ion-searchbar></ion-searchbar>
<ion-searchbar placeholder="Custom Placeholder"></ion-searchbar>
<ion-searchbar disabled="true" placeholder="Disabled"></ion-searchbar>
<ion-searchbar value="Value"></ion-searchbar>
<ion-searchbar animated="true" placeholder="Animated"></ion-searchbar>
</template>
<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
</script>
Search Icon
검색 아이콘은 searchbar의 입력 필드 왼쪽에 표시돼요. 어떤 Ionicon으로든 커스터마이즈할 수 있습니다.
JavaScript
<ion-searchbar></ion-searchbar>
<ion-searchbar search-icon="search-circle" placeholder="Custom Search Icon"></ion-searchbar>
Angular
src/app/example.component.html
<ion-searchbar></ion-searchbar>
<ion-searchbar search-icon="search-circle" placeholder="Custom Search Icon"></ion-searchbar>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';
import { addIcons } from 'ionicons';
import { searchCircle } from 'ionicons/icons';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonSearchbar],
})
export class ExampleComponent {
constructor() {
/**
* Any icons you want to use in your application
* can be registered in app.component.ts and then
* referenced by name anywhere in your application.
*/
addIcons({ searchCircle });
}
}
React
import React from 'react';
import { IonSearchbar } from '@ionic/react';
import { searchCircle } from 'ionicons/icons';
function Example() {
return (
<>
<IonSearchbar></IonSearchbar>
<IonSearchbar searchIcon={searchCircle} placeholder="Custom Search Icon"></IonSearchbar>
</>
);
}
export default Example;
Vue
<template>
<ion-searchbar></ion-searchbar>
<ion-searchbar :search-icon="searchCircle" placeholder="Custom Search Icon"></ion-searchbar>
</template>
<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
import { searchCircle } from 'ionicons/icons';
</script>
Clear Button
searchbar에 값이 있거나 입력 필드에 입력할 때 지우기(clear) 버튼이 표시돼요. 지우기 버튼을 클릭하면 텍스트 필드가 지워지고 입력은 포커스를 유지합니다. 기본적으로 지우기 버튼은 searchbar에 포커스를 맞출 때 표시되도록 설정되어 있지만, 항상 표시하거나 절대 표시하지 않도록 설정할 수도 있어요. 지우기 버튼 안의 아이콘도 어떤 Ionicon으로든 커스터마이즈할 수 있습니다.
JavaScript
<ion-searchbar show-clear-button="focus" value="Show on Focus"></ion-searchbar>
<ion-searchbar show-clear-button="always" value="Always Show"></ion-searchbar>
<ion-searchbar show-clear-button="never" value="Never Show"></ion-searchbar>
<ion-searchbar show-clear-button="always" clear-icon="trash-bin" value="Custom Clear Icon"></ion-searchbar>
Angular
src/app/example.component.html
<ion-searchbar show-clear-button="focus" value="Show on Focus"></ion-searchbar>
<ion-searchbar show-clear-button="always" value="Always Show"></ion-searchbar>
<ion-searchbar show-clear-button="never" value="Never Show"></ion-searchbar>
<ion-searchbar show-clear-button="always" clear-icon="trash-bin" value="Custom Clear Icon"></ion-searchbar>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';
import { addIcons } from 'ionicons';
import { trashBin } from 'ionicons/icons';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonSearchbar],
})
export class ExampleComponent {
constructor() {
/**
* Any icons you want to use in your application
* can be registered in app.component.ts and then
* referenced by name anywhere in your application.
*/
addIcons({ trashBin });
}
}
React
import React from 'react';
import { IonSearchbar } from '@ionic/react';
import { trashBin } from 'ionicons/icons';
function Example() {
return (
<>
<IonSearchbar showClearButton="focus" value="Show on Focus"></IonSearchbar>
<IonSearchbar showClearButton="always" value="Always Show"></IonSearchbar>
<IonSearchbar showClearButton="never" value="Never Show"></IonSearchbar>
<IonSearchbar showClearButton="always" clearIcon={trashBin} value="Custom Clear Icon"></IonSearchbar>
</>
);
}
export default Example;
Vue
<template>
<ion-searchbar show-clear-button="focus" value="Show on Focus"></ion-searchbar>
<ion-searchbar show-clear-button="always" value="Always Show"></ion-searchbar>
<ion-searchbar show-clear-button="never" value="Never Show"></ion-searchbar>
<ion-searchbar show-clear-button="always" :clear-icon="trashBin" value="Custom Clear Icon"></ion-searchbar>
</template>
<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
import { trashBin } from 'ionicons/icons';
</script>
Cancel Button
취소(cancel) 버튼을 활성화하면 클릭 시 입력을 지우고 포커스를 잃게 됩니다. 기본적으로 취소 버튼은 절대 표시되지 않도록 되어 있지만, 항상 표시하거나 searchbar에 포커스를 맞출 때만 표시하도록 설정할 수 있어요. 취소 버튼은 ios 모드에서는 텍스트로, md 모드에서는 아이콘으로 표시됩니다. 텍스트와 아이콘 모두 서로 다른 프로퍼티로 커스터마이즈할 수 있으며, 아이콘은 어떤 Ionicon도 받을 수 있어요.
JavaScript
<ion-searchbar show-cancel-button="focus" placeholder="Show on Focus"></ion-searchbar>
<ion-searchbar show-cancel-button="always" placeholder="Always Show"></ion-searchbar>
<ion-searchbar show-cancel-button="never" placeholder="Never Show"></ion-searchbar>
<ion-searchbar
show-cancel-button="always"
cancel-button-text="Custom Cancel"
cancel-button-icon="trash"
placeholder="Custom Cancel Button"
></ion-searchbar>
Angular
src/app/example.component.html
<ion-searchbar show-cancel-button="focus" placeholder="Show on Focus"></ion-searchbar>
<ion-searchbar show-cancel-button="always" placeholder="Always Show"></ion-searchbar>
<ion-searchbar show-cancel-button="never" placeholder="Never Show"></ion-searchbar>
<ion-searchbar
show-cancel-button="always"
cancel-button-text="Custom Cancel"
cancel-button-icon="trash"
placeholder="Custom Cancel Button"
></ion-searchbar>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';
import { addIcons } from 'ionicons';
import { trash } from 'ionicons/icons';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonSearchbar],
})
export class ExampleComponent {
constructor() {
/**
* Any icons you want to use in your application
* can be registered in app.component.ts and then
* referenced by name anywhere in your application.
*/
addIcons({ trash });
}
}
React
import React from 'react';
import { IonSearchbar } from '@ionic/react';
import { trash } from 'ionicons/icons';
function Example() {
return (
<>
<IonSearchbar showCancelButton="focus" placeholder="Show on Focus"></IonSearchbar>
<IonSearchbar showCancelButton="always" placeholder="Always Show"></IonSearchbar>
<IonSearchbar showCancelButton="never" placeholder="Never Show"></IonSearchbar>
<IonSearchbar
showCancelButton="always"
cancelButtonText="Custom Cancel"
cancelButtonIcon={trash}
placeholder="Custom Cancel Button"
></IonSearchbar>
</>
);
}
export default Example;
Vue
<template>
<ion-searchbar show-cancel-button="focus" placeholder="Show on Focus"></ion-searchbar>
<ion-searchbar show-cancel-button="always" placeholder="Always Show"></ion-searchbar>
<ion-searchbar show-cancel-button="never" placeholder="Never Show"></ion-searchbar>
<ion-searchbar
show-cancel-button="always"
cancel-button-text="Custom Cancel"
:cancel-button-icon="trash"
placeholder="Custom Cancel Button"
></ion-searchbar>
</template>
<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
import { trash } from 'ionicons/icons';
</script>
Searchbars in Toolbars
Searchbar는 툴바 안에 배치하면 네이티브처럼 보이도록 스타일링돼요. iOS에서 searchbar는 페이지 제목이 들어 있는 툴바 아래의 별도 툴바에 배치해야 합니다. Material Design에서 searchbar는 자체 툴바에 지속적으로 표시되거나, 페이지 제목이 들어 있는 툴바 위로 확장돼요.
JavaScript
<ion-header>
<ion-toolbar>
<ion-title>Toolbar</ion-title>
</ion-toolbar>
<ion-toolbar>
<ion-searchbar></ion-searchbar>
</ion-toolbar>
</ion-header>
Angular
src/app/example.component.html
<ion-header>
<ion-toolbar>
<ion-title>Toolbar</ion-title>
</ion-toolbar>
<ion-toolbar>
<ion-searchbar></ion-searchbar>
</ion-toolbar>
</ion-header>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonHeader, IonSearchbar, IonTitle, IonToolbar } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonHeader, IonSearchbar, IonTitle, IonToolbar],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonHeader, IonSearchbar, IonTitle, IonToolbar } from '@ionic/react';
function Example() {
return (
<IonHeader>
<IonToolbar>
<IonTitle>Toolbar</IonTitle>
</IonToolbar>
<IonToolbar>
<IonSearchbar></IonSearchbar>
</IonToolbar>
</IonHeader>
);
}
export default Example;
Vue
<template>
<ion-header>
<ion-toolbar>
<ion-title>Toolbar</ion-title>
</ion-toolbar>
<ion-toolbar>
<ion-searchbar></ion-searchbar>
</ion-toolbar>
</ion-header>
</template>
<script setup lang="ts">
import { IonHeader, IonSearchbar, IonTitle, IonToolbar } from '@ionic/vue';
</script>
Debounce
searchbar에 debounce를 설정하면 ionInput 이벤트 발생을 지연시킬 수 있어요. 이는 데이터를 조회할 때 유용한데, 입력에 문자가 입력될 때마다 매번 데이터를 요청하는 대신 잠시 기다렸다가 요청을 보낼 수 있기 때문입니다.
JavaScript
<ion-searchbar debounce="1000"></ion-searchbar>
<ion-list></ion-list>
<script>
const searchbar = document.querySelector('ion-searchbar');
const list = document.querySelector('ion-list');
const data = [
'Amsterdam',
'Buenos Aires',
'Cairo',
'Geneva',
'Hong Kong',
'Istanbul',
'London',
'Madrid',
'New York',
'Panama City',
];
let results = [...data];
filterItems(results);
searchbar.addEventListener('ionInput', handleInput);
function handleInput(event) {
const query = event.target.value.toLowerCase();
results = data.filter((d) => d.toLowerCase().indexOf(query) > -1);
filterItems(results);
}
function filterItems(results) {
list.replaceChildren();
let items = '';
for (let i = 0; i < results.length; i++) {
items += `
<ion-item>
<ion-label>${results[i]}</ion-label>
</ion-item>
`;
}
list.innerHTML = items;
}
</script>
Angular
src/app/example.component.html
<ion-searchbar [debounce]="1000" (ionInput)="handleInput($event)"></ion-searchbar>
<ion-list>
@for (result of results; track result) {
<ion-item>
<ion-label>{{ result }}</ion-label>
</ion-item>
}
</ion-list>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonItem, IonLabel, IonList, IonSearchbar } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonItem, IonLabel, IonList, IonSearchbar],
})
export class ExampleComponent {
public data = [
'Amsterdam',
'Buenos Aires',
'Cairo',
'Geneva',
'Hong Kong',
'Istanbul',
'London',
'Madrid',
'New York',
'Panama City',
];
public results = [...this.data];
handleInput(event: Event) {
const target = event.target as HTMLIonSearchbarElement;
const query = target.value?.toLowerCase() || '';
this.results = this.data.filter((d) => d.toLowerCase().includes(query));
}
}
React
import React, { useState } from 'react';
import { IonItem, IonList, IonSearchbar } from '@ionic/react';
function Example() {
const data = [
'Amsterdam',
'Buenos Aires',
'Cairo',
'Geneva',
'Hong Kong',
'Istanbul',
'London',
'Madrid',
'New York',
'Panama City',
];
let [results, setResults] = useState([...data]);
const handleInput = (event: Event) => {
let query = '';
const target = event.target as HTMLIonSearchbarElement;
if (target) query = target.value!.toLowerCase();
setResults(data.filter((d) => d.toLowerCase().indexOf(query) > -1));
};
return (
<>
<IonSearchbar debounce={1000} onIonInput={(event) => handleInput(event)}></IonSearchbar>
<IonList>
{results.map((result) => (
<IonItem>{result}</IonItem>
))}
</IonList>
</>
);
}
export default Example;
Vue
<template>
<ion-searchbar :debounce="1000" @ionInput="handleInput($event)"></ion-searchbar>
<ion-list>
<ion-item v-for="result in results">
<ion-label>{{ result }}</ion-label>
</ion-item>
</ion-list>
</template>
<script setup lang="ts">
import { IonItem, IonList, IonSearchbar } from '@ionic/vue';
import { ref } from 'vue';
const data = [
'Amsterdam',
'Buenos Aires',
'Cairo',
'Geneva',
'Hong Kong',
'Istanbul',
'London',
'Madrid',
'New York',
'Panama City',
];
const results = ref(data);
const handleInput = (event) => {
const query = event.target.value.toLowerCase();
results.value = data.filter((d) => d.toLowerCase().indexOf(query) > -1);
};
</script>
Theming
Colors
JavaScript
<ion-searchbar placeholder="Default"></ion-searchbar>
<ion-searchbar color="primary" placeholder="Primary"></ion-searchbar>
<ion-searchbar color="secondary" placeholder="Secondary"></ion-searchbar>
<ion-searchbar color="tertiary" placeholder="Tertiary"></ion-searchbar>
<ion-searchbar color="success" placeholder="Success"></ion-searchbar>
<ion-searchbar color="warning" placeholder="Warning"></ion-searchbar>
<ion-searchbar color="danger" placeholder="Danger"></ion-searchbar>
<ion-searchbar color="light" placeholder="Light"></ion-searchbar>
<ion-searchbar color="medium" placeholder="Medium"></ion-searchbar>
<ion-searchbar color="dark" placeholder="Dark"></ion-searchbar>
Angular
src/app/example.component.html
<ion-searchbar placeholder="Default"></ion-searchbar>
<ion-searchbar color="primary" placeholder="Primary"></ion-searchbar>
<ion-searchbar color="secondary" placeholder="Secondary"></ion-searchbar>
<ion-searchbar color="tertiary" placeholder="Tertiary"></ion-searchbar>
<ion-searchbar color="success" placeholder="Success"></ion-searchbar>
<ion-searchbar color="warning" placeholder="Warning"></ion-searchbar>
<ion-searchbar color="danger" placeholder="Danger"></ion-searchbar>
<ion-searchbar color="light" placeholder="Light"></ion-searchbar>
<ion-searchbar color="medium" placeholder="Medium"></ion-searchbar>
<ion-searchbar color="dark" placeholder="Dark"></ion-searchbar>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonSearchbar],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonSearchbar } from '@ionic/react';
function Example() {
return (
<>
<IonSearchbar placeholder="Default"></IonSearchbar>
<IonSearchbar color="primary" placeholder="Primary"></IonSearchbar>
<IonSearchbar color="secondary" placeholder="Secondary"></IonSearchbar>
<IonSearchbar color="tertiary" placeholder="Tertiary"></IonSearchbar>
<IonSearchbar color="success" placeholder="Success"></IonSearchbar>
<IonSearchbar color="warning" placeholder="Warning"></IonSearchbar>
<IonSearchbar color="danger" placeholder="Danger"></IonSearchbar>
<IonSearchbar color="light" placeholder="Light"></IonSearchbar>
<IonSearchbar color="medium" placeholder="Medium"></IonSearchbar>
<IonSearchbar color="dark" placeholder="Dark"></IonSearchbar>
</>
);
}
export default Example;
Vue
<template>
<ion-searchbar placeholder="Default"></ion-searchbar>
<ion-searchbar color="primary" placeholder="Primary"></ion-searchbar>
<ion-searchbar color="secondary" placeholder="Secondary"></ion-searchbar>
<ion-searchbar color="tertiary" placeholder="Tertiary"></ion-searchbar>
<ion-searchbar color="success" placeholder="Success"></ion-searchbar>
<ion-searchbar color="warning" placeholder="Warning"></ion-searchbar>
<ion-searchbar color="danger" placeholder="Danger"></ion-searchbar>
<ion-searchbar color="light" placeholder="Light"></ion-searchbar>
<ion-searchbar color="medium" placeholder="Medium"></ion-searchbar>
<ion-searchbar color="dark" placeholder="Dark"></ion-searchbar>
</template>
<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
</script>
CSS Custom Properties
Searchbar는 scoped 캡슐화를 사용해요. 즉 런타임에 각 스타일에 추가 클래스를 덧붙여 CSS를 자동으로 스코프 처리합니다. scoped 선택자를 CSS에서 덮어쓰려면 더 높은 특이성(specificity)의 선택자가 필요해요. 커스터마이즈를 위해 ion-searchbar만 타겟하는 것은 동작하지 않으므로, 클래스를 추가하고 그 클래스로 커스터마이즈하는 것을 권장합니다.
JavaScript
<ion-searchbar show-cancel-button="focus" class="custom"></ion-searchbar>
<style>
/* Scoped components require higher specificity to customize */
ion-searchbar.custom {
--background: #19422d;
--color: #fff;
--placeholder-color: #fff;
--icon-color: #fff;
--clear-button-color: #fff;
--border-radius: 4px;
}
ion-searchbar.ios.custom {
--cancel-button-color: #19422d;
}
ion-searchbar.md.custom {
--cancel-button-color: #fff;
}
</style>
Angular
src/app/example.component.html
<ion-searchbar showCancelButton="focus" class="custom"></ion-searchbar>
src/app/example.component.css
/* Scoped components require higher specificity to customize */
ion-searchbar.custom {
--background: #19422d;
--color: #fff;
--placeholder-color: #fff;
--icon-color: #fff;
--clear-button-color: #fff;
--border-radius: 4px;
}
ion-searchbar.ios.custom {
--cancel-button-color: #19422d;
}
ion-searchbar.md.custom {
--cancel-button-color: #fff;
}
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonSearchbar],
})
export class ExampleComponent {}
React
src/main.tsx
import React from 'react';
import { IonSearchbar } from '@ionic/react';
import './main.css';
function Example() {
return <IonSearchbar showCancelButton="focus" class="custom"></IonSearchbar>;
}
export default Example;
src/main.css
/* Scoped components require higher specificity to customize */
ion-searchbar.custom {
--background: #19422d;
--color: #fff;
--placeholder-color: #fff;
--icon-color: #fff;
--clear-button-color: #fff;
--border-radius: 4px;
}
ion-searchbar.ios.custom {
--cancel-button-color: #19422d;
}
ion-searchbar.md.custom {
--cancel-button-color: #fff;
}
Vue
<template>
<ion-searchbar showCancelButton="focus" class="custom"></ion-searchbar>
</template>
<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
</script>
<style scoped>
/* Scoped components require higher specificity to customize */
ion-searchbar.custom {
--background: #19422d;
--color: #fff;
--placeholder-color: #fff;
--icon-color: #fff;
--clear-button-color: #fff;
--border-radius: 4px;
}
ion-searchbar.ios.custom {
--cancel-button-color: #19422d;
}
ion-searchbar.md.custom {
--cancel-button-color: #fff;
}
</style>
Keyboard Display
Android
기본적으로 입력을 탭하면 제출(submit) 버튼에 돋보기 아이콘이 있는 키보드가 나타나요. 선택적으로 inputmode 프로퍼티를 "search"로 설정하면 아이콘이 돋보기에서 캐리지 리턴으로 바뀝니다.
iOS
기본적으로 입력을 탭하면 회색 제출 버튼에 "return" 텍스트가 있는 키보드가 나타나요. 선택적으로 inputmode 프로퍼티를 "search"로 설정하면 텍스트가 "return"에서 "go"로, 버튼 색상이 회색에서 파란색으로 바뀝니다. 또는 ion-searchbar를 action 프로퍼티가 있는 form 요소로 감쌀 수도 있어요. 그러면 "search"라고 쓰여 있는 파란색 제출 버튼이 있는 키보드가 나타납니다.
Interfaces
SearchbarChangeEventDetail
interface SearchbarChangeEventDetail {
value?: string;
}
SearchbarCustomEvent
필수는 아니지만, 이 컴포넌트에서 발생하는 Ionic 이벤트에 대해 더 강력한 타입을 제공하려면 CustomEvent 인터페이스 대신 이 인터페이스를 사용할 수 있어요.
interface SearchbarCustomEvent extends CustomEvent {
detail: SearchbarChangeEventDetail;
target: HTMLIonSearchbarElement;
}
Properties
animated
Description: true로 설정하면 searchbar 애니메이션을 활성화해요.
Attribute: animated
Type: boolean
Default: false
autocapitalize
Description: 사용자가 입력/편집할 때 텍스트 값을 자동으로 대문자 처리할지 여부와 방법을 나타내요. 사용 가능한 옵션: "off", "none", "on", "sentences", "words", "characters".
Attribute: autocapitalize
Type: string
Default: 'off'
autocomplete
Description: 입력의 autocomplete 프로퍼티를 설정해요.
Attribute: autocomplete
Type: "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"
Default: 'off'
autocorrect
Description: 입력의 autocorrect 프로퍼티를 설정해요.
Attribute: autocorrect
Type: boolean
Default: false
cancelButtonIcon
Description: 취소 버튼 아이콘을 설정해요. md 모드에서만 적용됩니다. 기본값은 arrow-back-sharp이에요.
Attribute: cancel-button-icon
Type: string
Default: config.get('backButtonIcon', arrowBackSharp) as string
cancelButtonText
Description: 취소 버튼 텍스트를 설정해요. ios 모드에서만 적용됩니다.
Attribute: cancel-button-text
Type: string
Default: 'Cancel'
clearIcon
Description: 지우기 아이콘을 설정해요. ios에서는 close-circle, md에서는 close-sharp이 기본값이에요.
Attribute: clear-icon
Type: string | undefined
Default: undefined
color
Description: 애플리케이션의 컬러 팔레트에서 사용할 색상이에요. 기본 옵션은 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", "dark"입니다. 색상에 대한 자세한 내용은 theming을 참고하세요.
Attribute: color
Type: "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined
Default: undefined
debounce
Description: 각 키 입력 후 ionInput 이벤트를 발생시키기까지 기다릴 시간(밀리초)을 설정해요.
Attribute: debounce
Type: number | undefined
Default: undefined
disabled
Description: true로 설정하면 사용자가 입력과 상호작용할 수 없어요.
Attribute: disabled
Type: boolean
Default: false
enterkeyhint
Description: 브라우저에 표시할 엔터 키에 대한 힌트예요. 가능한 값: "enter", "done", "go", "next", "previous", "search", "send".
Attribute: enterkeyhint
Type: "done" | "enter" | "go" | "next" | "previous" | "search" | "send" | undefined
Default: undefined
inputmode
Description: 브라우저에 표시할 키보드에 대한 힌트예요. 가능한 값: "none", "text", "tel", "url", "email", "numeric", "decimal", "search".
Attribute: inputmode
Type: "decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined
Default: undefined
maxlength
Description: 이 속성은 사용자가 입력할 수 있는 문자의 최대 개수를 지정해요.
Attribute: maxlength
Type: number | undefined
Default: undefined
minlength
Description: 이 속성은 사용자가 입력할 수 있는 문자의 최소 개수를 지정해요.
Attribute: minlength
Type: number | undefined
Default: undefined
mode
Description: 모드는 어떤 플랫폼 스타일을 사용할지 결정해요. 이 값은 초기화 중에 한 번 설정되며 초기 렌더 후 값을 변경해도 업데이트되지 않는 가상 프로퍼티예요.
Attribute: mode
Type: "ios" | "md"
Default: undefined
name
Description: 폼에서 사용된다면, 폼 데이터와 함께 제출되는 컨트롤의 이름을 설정해요.
Attribute: name
Type: string
Default: this.inputId
placeholder
Description: 입력의 placeholder를 설정해요. placeholder는 일반 텍스트나 HTML을 문자열로 받을 수 있습니다. HTML에서 보통 예약된 문자를 표시하려면 이스케이프해야 해요. 예를 들어 <Ionic>은 <Ionic>으로 표시됩니다. 자세한 내용: Security Documentation
Attribute: placeholder
Type: string
Default: 'Search'
searchIcon
Description: 검색 아이콘으로 사용할 아이콘이에요. ios 모드에서는 search-outline, md 모드에서는 search-sharp이 기본값입니다.
Attribute: search-icon
Type: string | undefined
Default: undefined
showCancelButton
Description: 취소 버튼의 동작을 설정해요. 기본값은 "never"입니다. "focus"로 설정하면 포커스 시 취소 버튼을 보여줍니다. "never"로 설정하면 취소 버튼을 숨겨요. "always"로 설정하면 포커스 상태와 관계없이 취소 버튼을 보여줍니다.
Attribute: show-cancel-button
Type: "always" | "focus" | "never"
Default: 'never'
showClearButton
Description: 지우기 버튼의 동작을 설정해요. 기본값은 "focus"입니다. "focus"로 설정하면 포커스 시 입력이 비어 있지 않을 때 지우기 버튼을 보여줍니다. "never"로 설정하면 지우기 버튼을 숨겨요. "always"로 설정하면 포커스 상태와 관계없이 입력이 비어 있지 않을 때 지우기 버튼을 보여줍니다.
Attribute: show-clear-button
Type: "always" | "focus" | "never"
Default: 'always'
spellcheck
Description: true로 설정하면 입력에서 맞춤법 검사를 활성화해요.
Attribute: spellcheck
Type: boolean
Default: false
type
Description: 입력의 타입을 설정해요.
Attribute: type
Type: "email" | "number" | "password" | "search" | "tel" | "text" | "url"
Default: 'search'
value
Description: searchbar의 값이에요.
Attribute: value
Type: null | string | undefined
Default: ''
Events
| Name | Description | Bubbles |
|---|---|---|
ionBlur |
입력이 포커스를 잃을 때 발생해요. | true |
ionCancel |
취소 버튼이 클릭될 때 발생해요. | true |
ionChange |
사용자가 요소의 값을 수정할 때 <ion-searchbar> 요소에서 ionChange 이벤트가 발생해요. ionInput 이벤트와 달리, ionChange 이벤트는 요소 값의 모든 변경마다 반드시 발생하지는 않습니다. ionChange 이벤트는 값이 사용자에 의해 확정(commit)되었을 때 발생해요. 이는 요소가 포커스를 잃거나 "Enter" 키가 눌릴 때 일어날 수 있어요. ionChange는 지우기 또는 취소 버튼을 클릭할 때도 발생할 수 있습니다. value 프로퍼티를 프로그래밍 방식으로 설정할 때는 이 이벤트가 발생하지 않아요. |
true |
ionClear |
지우기 입력 버튼이 클릭될 때 발생해요. | true |
ionFocus |
입력이 포커스를 가질 때 발생해요. | true |
ionInput |
ion-searchbar 요소의 value가 변경되었을 때 발생해요. |
true |
Methods
getInputElement
Description: 내부에서 사용하는 네이티브 <input> 요소를 반환해요.
Signature: getInputElement() => Promise<HTMLInputElement>
setFocus
Description: ion-searchbar의 네이티브 input에 포커스를 설정해요. 전역 input.focus() 대신 이 메서드를 사용하세요. 페이지 진입 시 입력에 포커스를 두고 싶은 개발자는 ionViewDidEnter() 생명주기 메서드에서 setFocus()를 호출해야 합니다. 오버레이가 표시될 때 입력에 포커스를 두고 싶은 개발자는 didPresent가 resolve된 후 setFocus를 호출해야 해요. 자세한 내용은 managing focus를 참고하세요.
Signature: setFocus() => Promise<void>
CSS Shadow Parts
이 컴포넌트에는 사용할 수 있는 CSS shadow part가 없어요.
CSS Custom Properties
iOS
| Name | Description |
|---|---|
--background |
searchbar 입력의 배경색(Background of the searchbar input) |
--border-radius |
searchbar 입력의 테두리 반경(Border radius of the searchbar input) |
--box-shadow |
searchbar 입력의 박스 섀도(Box shadow of the searchbar input) |
--cancel-button-color |
searchbar 취소 버튼의 색상(Color of the searchbar cancel button) |
--clear-button-color |
searchbar 지우기 버튼의 색상(Color of the searchbar clear button) |
--color |
searchbar 텍스트의 색상(Color of the searchbar text) |
--icon-color |
searchbar 아이콘의 색상(Color of the searchbar icon) |
--placeholder-color |
searchbar placeholder의 색상(Color of the searchbar placeholder) |
--placeholder-font-style |
searchbar placeholder의 폰트 스타일(Font style of the searchbar placeholder) |
--placeholder-font-weight |
searchbar placeholder의 폰트 두께(Font weight of the searchbar placeholder) |
--placeholder-opacity |
searchbar placeholder의 투명도(Opacity of the searchbar placeholder) |
MD
| Name | Description |
|---|---|
--background |
searchbar 입력의 배경색(Background of the searchbar input) |
--border-radius |
searchbar 입력의 테두리 반경(Border radius of the searchbar input) |
--box-shadow |
searchbar 입력의 박스 섀도(Box shadow of the searchbar input) |
--cancel-button-color |
searchbar 취소 버튼의 색상(Color of the searchbar cancel button) |
--clear-button-color |
searchbar 지우기 버튼의 색상(Color of the searchbar clear button) |
--color |
searchbar 텍스트의 색상(Color of the searchbar text) |
--icon-color |
searchbar 아이콘의 색상(Color of the searchbar icon) |
--placeholder-color |
searchbar placeholder의 색상(Color of the searchbar placeholder) |
--placeholder-font-style |
searchbar placeholder의 폰트 스타일(Font style of the searchbar placeholder) |
--placeholder-font-weight |
searchbar placeholder의 폰트 두께(Font weight of the searchbar placeholder) |
--placeholder-opacity |
searchbar placeholder의 투명도(Opacity of the searchbar placeholder) |
Slots
이 컴포넌트에는 사용할 수 있는 슬롯이 없어요.
더 알아보기 (Learn more)
ion-searchbar는 목록을 검색하는 데 최적화된 입력 필드예요. 검색·지우기·취소 아이콘/버튼을 바꿀 수 있고, debounce로 입력 지연을 주고 ionInput/ionChange 이벤트로 검색 로직을 연결할 수 있어요. 툴바 안에 넣으면 네이티브처럼 보이게 스타일링됩니다.