Skip to content
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

fix(kselect): clear filter on blur [KHCP-13444] #2486

Merged
merged 4 commits into from
Oct 29, 2024
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
10 changes: 9 additions & 1 deletion src/components/KMultiselect/KMultiselect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
}
}"
@focus="onInputFocus"
@keydown.enter="onInputEnter"
@keyup="(evt: any) => triggerFocus(evt, isToggled)"
@mouseenter="() => isHovered = true"
@mouseleave="() => isHovered = false"
Expand Down Expand Up @@ -170,6 +171,7 @@
type="text"
@click.stop
@focus="triggerInitialFocus"
@keydown.enter="onInputEnter"
@keyup="onDropdownInputKeyup"
@keyup.enter.stop
@update:model-value="onQueryChange"
Expand Down Expand Up @@ -815,9 +817,15 @@ const handleItemSelect = (item: MultiselectItem, isNew?: boolean) => {
emit('update:modelValue', selectedVals)
}

const onInputEnter = (): void => {
if (!filteredItems.value.length && props.enableItemCreation) {
handleAddItem()
}
}

// add an item with `enter`
const handleAddItem = (): void => {
if (!props.enableItemCreation || !filterString.value || !uniqueFilterStr.value) {
if (!props.enableItemCreation || !filterString.value || !uniqueFilterStr.value || !props.itemCreationValidator(filterString.value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non blocking: It seems that we are missing itemCreationValidator in <KSelect>, shall we align this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already have a PR for this: #2485

// do nothing if not enabled or no label or label already exists
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/KSelect/KSelect.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('KSelect', () => {
cy.getTestId(`select-item-${vals[0]}`).should('contain.text', labels[0])
cy.getTestId(`select-item-${vals[1]}`).should('not.exist')

cy.getTestId(`select-item-${vals[0]}`).eq(0).click({ force: true })
cy.getTestId(`select-item-${vals[0]}`).click()
cy.getTestId('select-input').should('have.value', labels[0])
})

Expand Down
9 changes: 9 additions & 0 deletions src/components/KSelect/KSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
@blur="onInputBlur"
@click="onInputClick"
@focus="onInputFocus"
@keydown.enter="onInputEnter"
@keypress="onInputKeypress"
@keyup="(evt: any) => triggerFocus(evt, isToggled)"
@keyup.enter.stop
Expand Down Expand Up @@ -477,6 +478,12 @@ const onInputKeypress = (event: Event) => {
}
}

const onInputEnter = (): void => {
if (!filteredItems.value.length && props.enableItemCreation) {
handleAddItem()
}
}

const handleAddItem = (): void => {
if (!props.enableItemCreation || !filterQuery.value || !uniqueFilterQuery.value) {
// do nothing if not enabled or no label or label already exists
Expand Down Expand Up @@ -607,6 +614,8 @@ const onClose = (toggle: () => void, isToggled: boolean) => {

if (selectedItem.value) {
filterQuery.value = selectedItem.value.label
} else {
filterQuery.value = ''
}

if (isToggled) {
Expand Down