Skip to content

docs(searchbar): debounce uses ionInput #2913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/searchbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import Toolbar from '@site/static/usage/v7/toolbar/searchbars/index.md';

## Debounce

A debounce can be set on the searchbar in order to delay triggering the `ionChange` event. This is useful when querying data, as it can be used to wait to make a request instead of requesting the data each time a character is entered in the input.
A debounce can be set on the searchbar in order to delay triggering the `ionInput` event. This is useful when querying data, as it can be used to wait to make a request instead of requesting the data each time a character is entered in the input.

import Debounce from '@site/static/usage/v7/searchbar/debounce/index.md';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```html
<ion-searchbar [debounce]="1000" (ionChange)="handleChange($event)"></ion-searchbar>
<ion-searchbar [debounce]="1000" (ionInput)="handleInput($event)"></ion-searchbar>

<ion-list>
<ion-item *ngFor="let result of results">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ExampleComponent {
public data = ['Amsterdam', 'Buenos Aires', 'Cairo', 'Geneva', 'Hong Kong', 'Istanbul', 'London', 'Madrid', 'New York', 'Panama City'];
public results = [...this.data];

handleChange(event) {
handleInput(event) {
const query = event.target.value.toLowerCase();
this.results = this.data.filter(d => d.toLowerCase().indexOf(query) > -1);
}
Expand Down
6 changes: 3 additions & 3 deletions static/usage/v7/searchbar/debounce/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
let results = [...data];
filterItems(results);

searchbar.addEventListener('ionChange', handleChange);
searchbar.addEventListener('ionInput', handleInput);

function handleChange(event) {
function handleInput(event) {
const query = event.target.value.toLowerCase();
results = data.filter(d => d.toLowerCase().indexOf(query) > -1);
filterItems(results);
Expand All @@ -61,4 +61,4 @@
}
</script>

</html>
</html>
4 changes: 2 additions & 2 deletions static/usage/v7/searchbar/debounce/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
let results = [...data];
filterItems(results);

searchbar.addEventListener('ionChange', handleChange);
searchbar.addEventListener('ionInput', handleInput);

function handleChange(event) {
function handleInput(event) {
const query = event.target.value.toLowerCase();
results = data.filter(d => d.toLowerCase().indexOf(query) > -1);
filterItems(results);
Expand Down
4 changes: 2 additions & 2 deletions static/usage/v7/searchbar/debounce/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Example() {
const data = ['Amsterdam', 'Buenos Aires', 'Cairo', 'Geneva', 'Hong Kong', 'Istanbul', 'London', 'Madrid', 'New York', 'Panama City'];
let [results, setResults] = useState([...data]);

const handleChange = (ev: Event) => {
const handleInput = (ev: Event) => {
let query = "";
const target = ev.target as HTMLIonSearchbarElement;
if (target) query = target.value!.toLowerCase();
Expand All @@ -16,7 +16,7 @@ function Example() {

return (
<>
<IonSearchbar debounce={1000} onIonChange={(ev) => handleChange(ev)}></IonSearchbar>
<IonSearchbar debounce={1000} onIonInput={(ev) => handleInput(ev)}></IonSearchbar>

<IonList>
{ results.map(result => (
Expand Down
4 changes: 2 additions & 2 deletions static/usage/v7/searchbar/debounce/vue.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```html
<template>
<ion-searchbar :debounce="1000" @ionChange="handleChange($event)"></ion-searchbar>
<ion-searchbar :debounce="1000" @ionInput="handleInput($event)"></ion-searchbar>

<ion-list>
<ion-item v-for="result in results">
Expand All @@ -22,7 +22,7 @@
return { data, results };
},
methods: {
handleChange(event) {
handleInput(event) {
const query = event.target.value.toLowerCase();
this.results = this.data.filter(d => d.toLowerCase().indexOf(query) > -1);
},
Expand Down