fix: missing last typed letter on filter tree event

pull/6963/head
Erwan Le Forestier 2024-12-13 16:36:54 +01:00
parent 537772da64
commit 505c0e7ef9
2 changed files with 10 additions and 5 deletions

View File

@ -48,11 +48,16 @@ describe('Tree.vue', () => {
} }
}); });
let searchField = wrapper.find('input.p-inputtext'); let searchField = wrapper.find('input.p-inputtext');
const key = 't';
searchField.element.value = key;
await searchField.trigger('keydown.space'); await searchField.trigger('keyup', {
key
});
expect(wrapper.emitted('filter')).toBeTruthy(); expect(wrapper.emitted('filter')).toBeTruthy();
expect(wrapper.emitted('filter')[0][0].value).toEqual(key);
}); });
it('should render icon', ({ expect }) => { it('should render icon', ({ expect }) => {

View File

@ -9,7 +9,7 @@
</div> </div>
</template> </template>
<IconField v-if="filter" :unstyled="unstyled" :pt="{ ...ptm('pcFilter'), ...ptm('pcFilterContainer') }" :class="cx('pcFilterContainer')"> <IconField v-if="filter" :unstyled="unstyled" :pt="{ ...ptm('pcFilter'), ...ptm('pcFilterContainer') }" :class="cx('pcFilterContainer')">
<InputText v-model="filterValue" autocomplete="off" :class="cx('pcFilterInput')" :placeholder="filterPlaceholder" :unstyled="unstyled" @keydown="onFilterKeydown" :pt="ptm('pcFilterInput')" /> <InputText v-model="filterValue" autocomplete="off" :class="cx('pcFilterInput')" :placeholder="filterPlaceholder" :unstyled="unstyled" @keyup="onFilterKeyup" :pt="ptm('pcFilterInput')" />
<InputIcon :unstyled="unstyled" :pt="ptm('pcFilterIconContainer')"> <InputIcon :unstyled="unstyled" :pt="ptm('pcFilterIconContainer')">
<!--TODO: searchicon deprecated since v4.0--> <!--TODO: searchicon deprecated since v4.0-->
<slot :name="$slots.filtericon ? 'filtericon' : 'searchicon'" :class="cx('filterIcon')"> <slot :name="$slots.filtericon ? 'filtericon' : 'searchicon'" :class="cx('filterIcon')">
@ -172,7 +172,7 @@ export default {
isNodeLeaf(node) { isNodeLeaf(node) {
return node.leaf === false ? false : !(node.children && node.children.length); return node.leaf === false ? false : !(node.children && node.children.length);
}, },
onFilterKeydown(event) { onFilterKeyup(event) {
if (event.code === 'Enter' || event.code === 'NumpadEnter') { if (event.code === 'Enter' || event.code === 'NumpadEnter') {
event.preventDefault(); event.preventDefault();
} }