Skip to content

Commit

Permalink
Supplant mousedown handler for ft-icon-button
Browse files Browse the repository at this point in the history
  • Loading branch information
kommunarr committed Jun 3, 2024
1 parent 4f5f3c1 commit d18b549
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
16 changes: 3 additions & 13 deletions src/renderer/components/ft-icon-button/ft-icon-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default defineComponent({
data: function () {
return {
dropdownShown: false,
mouseDownOnIcon: false,
useModal: false
}
},
Expand Down Expand Up @@ -111,24 +110,15 @@ export default defineComponent({
}
},

handleIconMouseDown: function () {
if (this.disabled) { return }
if (this.dropdownShown) {
this.mouseDownOnIcon = true
}
},

handleDropdownFocusOut: function () {
if (this.mouseDownOnIcon) {
this.mouseDownOnIcon = false
} else if (!this.$refs.dropdown.matches(':focus-within')) {
if (this.dropdownShown && !this.$refs.ftIconButton.matches(':focus-within')) {
this.dropdownShown = false
}
},

handleDropdownEscape: function () {
this.$refs.iconButton.focus()
// handleDropdownFocusOut will hide the dropdown for us
this.dropdownShown = false
this.$refs.ftIconButton.firstElementChild.focus()
},

handleDropdownClick: function ({ url, index }) {
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/components/ft-icon-button/ft-icon-button.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div class="ftIconButton">
<div
ref="ftIconButton"
class="ftIconButton"
@focusout="handleDropdownFocusOut"
>
<font-awesome-icon
ref="iconButton"
class="iconButton"
:title="title"
:icon="icon"
Expand All @@ -19,7 +22,6 @@
:aria-disabled="disabled"
:aria-expanded="dropdownShown"
@click="handleIconClick"
@mousedown="handleIconMouseDown"
@keydown.enter.prevent="handleIconClick"
@keydown.space.prevent="handleIconClick"
/>
Expand Down Expand Up @@ -67,7 +69,6 @@
bottom: dropdownPositionY === 'bottom',
top: dropdownPositionY === 'top'
}"
@focusout="handleDropdownFocusOut"
@keydown.esc.stop="handleDropdownEscape"
>
<slot>
Expand Down

0 comments on commit d18b549

Please sign in to comment.