Skip to content

Commit

Permalink
Fixed #359 - Filter event for Listbox, Dropdown and MultiSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Jul 4, 2020
1 parent 9ba8911 commit 9e76c66
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/dropdown/Dropdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export declare class Dropdown extends Vue {
$emit(eventName: 'before-leave'): this;
$emit(eventName: 'show'): this;
$emit(eventName: 'hide'): this;
$emit(eventName: 'filter', e: { originalEvent: Event, value: string }): this;
$slot: {
option: VNode[];
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div ref="overlay" class="p-dropdown-panel p-component" v-if="overlayVisible">
<div class="p-dropdown-header" v-if="filter">
<div class="p-dropdown-filter-container">
<input type="text" ref="filterInput" v-model="filterValue" autoComplete="off" class="p-dropdown-filter p-inputtext p-component" :placeholder="filterPlaceholder" @keydown="onFilterKeyDown" />
<input type="text" ref="filterInput" v-model="filterValue" autoComplete="off" class="p-dropdown-filter p-inputtext p-component" :placeholder="filterPlaceholder" @keydown="onFilterKeyDown" @input="onFilterChange"/>
<span class="p-dropdown-filter-icon pi pi-search"></span>
</div>
</div>
Expand Down Expand Up @@ -407,6 +407,9 @@ export default {
else
document.getElementById(this.appendTo).removeChild(this.$refs.overlay);
}
},
onFilterChange(event) {
this.$emit('filter', {originalEvent: event, value: event.target.value});
}
},
computed: {
Expand Down
1 change: 1 addition & 0 deletions src/components/listbox/Listbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export declare class Listbox extends Vue {
ariaLabelledBy?: string;
$emit(eventName: 'input', value: any): this;
$emit(eventName: 'change', e: { originalEvent: Event, value: any }): this;
$emit(eventName: 'filter', e: { originalEvent: Event, value: string }): this;
$slots: {
option: VNode[];
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/listbox/Listbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="p-listbox p-component">
<div class="p-listbox-header" v-if="filter">
<div class="p-listbox-filter-container">
<input type="text" class="p-listbox-filter p-inputtext p-component" v-model="filterValue" :placeholder="filterPlaceholder">
<input type="text" class="p-listbox-filter p-inputtext p-component" v-model="filterValue" :placeholder="filterPlaceholder" @input="onFilterChange">
<span class="p-listbox-filter-icon pi pi-search"></span>
</div>
</div>
Expand Down Expand Up @@ -216,6 +216,9 @@ export default {
return DomHandler.hasClass(prevItem, 'p-disabled') ? this.findPrevItem(prevItem) : prevItem;
else
return null;
},
onFilterChange(event) {
this.$emit('filter', {originalEvent: event, value: event.target.value});
}
},
computed: {
Expand Down
1 change: 1 addition & 0 deletions src/components/multiselect/MultiSelect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export declare class MultiSelect extends Vue {
$emit(eventName: 'before-leave'): this;
$emit(eventName: 'show'): this;
$emit(eventName: 'hide'): this;
$emit(eventName: 'filter', e: { originalEvent: Event, value: string }): this;
$slots: {
value: VNode[];
option: VNode[];
Expand Down
5 changes: 4 additions & 1 deletion src/components/multiselect/MultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>
</div>
<div v-if="filter" class="p-multiselect-filter-container">
<input type="text" v-model="filterValue" class="p-multiselect-filter p-inputtext p-component" :placeholder="filterPlaceholder">
<input type="text" v-model="filterValue" class="p-multiselect-filter p-inputtext p-component" :placeholder="filterPlaceholder" @input="onFilterChange">
<span class="p-multiselect-filter-icon pi pi-search"></span>
</div>
<button class="p-multiselect-close p-link" @click="onCloseClick" type="button" v-ripple>
Expand Down Expand Up @@ -339,6 +339,9 @@ export default {
else
document.getElementById(this.appendTo).removeChild(this.$refs.overlay);
}
},
onFilterChange(event) {
this.$emit('filter', {originalEvent: event, value: event.target.value});
}
},
computed: {
Expand Down
6 changes: 6 additions & 0 deletions src/views/dropdown/DropdownDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ data() {
<td>hide</td>
<td>-</td>
<td>Callback to invoke when the overlay is hidden.</td>
</tr>
<tr>
<td>filter</td>
<td>event.originalEvent: Original event <br />
event.value: Filter value </td>
<td>Callback to invoke on filter input.</td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 6 additions & 0 deletions src/views/listbox/ListboxDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ data() {
<td>input</td>
<td>value: New value</td>
<td>Callback to invoke on value change.</td>
</tr>
<tr>
<td>filter</td>
<td>event.originalEvent: Original event <br />
event.value: Filter value </td>
<td>Callback to invoke on filter input.</td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 6 additions & 0 deletions src/views/multiselect/MultiSelectDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ data() {
<td>-</td>
<td>Callback to invoke when the overlay is hidden.</td>
</tr>
<tr>
<td>filter</td>
<td>event.originalEvent: Original event <br />
event.value: Filter value </td>
<td>Callback to invoke on filter input.</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 9e76c66

Please sign in to comment.