Skip to content

Commit

Permalink
fix(kinput): prevent focus loss on icon/button click (#2453)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo authored Oct 15, 2024
1 parent 7201572 commit c536de7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/KInput/KInput.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ describe('KInput', () => {

cy.get('.k-input .mask-value-toggle-button').should('be.visible')
cy.get('.k-input input').should('have.attr', 'type', 'password')
cy.get('.k-input input').focus()
cy.get('.k-input .mask-value-toggle-button').click()
cy.get('.k-input input').should('have.attr', 'type', 'text')
cy.get('.k-input .mask-value-toggle-button').click()
cy.get('.k-input input').should('have.attr', 'type', 'password')

cy.get('.k-input input').should('have.attr', 'type', 'password').should('be.focused')
// user-provided after slot should be rendered
cy.get('.k-input').find(`[data-testid="${afterSlot}"]`).should('not.exist')
})
Expand Down
8 changes: 8 additions & 0 deletions src/components/KInput/KInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
:aria-label="`${maskValue ? 'Hide' : 'Show'} value`"
class="mask-value-toggle-button"
@click.stop="maskValue = !maskValue"
@mousedown.prevent
@mouseup.prevent
>
<VisibilityOffIcon
v-if="maskValue"
Expand Down Expand Up @@ -384,6 +386,12 @@ $kInputSlotSpacing: var(--kui-space-40, $kui-space-40); // $kSelectInputSlotSpac
width: $kInputIconSize !important;
}
// enhance the experience for most common cases that icon only slots should not
// prevent the input from being focused by click on the icon
&:has(> #{$kongponentsKongIconSelector}:not(button):not([role="button"]):only-child) {
pointer-events: none;
}
:deep([role="button"]:not(.k-button)), :deep(button:not(.k-button)),
.mask-value-toggle-button {
@include defaultButtonReset;
Expand Down

0 comments on commit c536de7

Please sign in to comment.