Skip to content
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
1 change: 1 addition & 0 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
>
<portal-target
name="promptPortal"
multiple
@change="handlePromptPortalUpdate"
/>
<ft-prompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<ft-prompt
theme="flex-column"
:label="title"
:inert="showingCreatePlaylistPrompt"
@click="hide"
>
<h2 class="heading">
Expand Down
34 changes: 19 additions & 15 deletions src/renderer/components/ft-prompt/ft-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export default defineComponent({
theme: {
type: String,
default: 'base'
},
inert: {
type: Boolean,
default: false
}
},
emits: ['click'],
Expand All @@ -56,14 +60,9 @@ export default defineComponent({
},
mounted: function () {
this.lastActiveElement = document.activeElement
this.$nextTick(() => {
nextTick(() => {
document.addEventListener('keydown', this.closeEventFunction, true)
document.querySelector('.prompt').addEventListener('keydown', this.arrowKeys, true)
this.promptButtons = Array.from(
document.querySelector('.prompt .promptCard .ft-flex-box').childNodes
).filter((e) => {
return e.id && e.id.startsWith('prompt')
})
this.promptButtons = Array.from(this.$refs.promptCard.$el.querySelectorAll('.btn.ripple'))
this.focusItem(0)
})
},
Expand Down Expand Up @@ -115,20 +114,25 @@ export default defineComponent({
},
// close on escape key and unfocus
closeEventFunction: function(event) {
if (event.type === 'keydown' && event.key === 'Escape') {
if (event.type === 'keydown' && event.key === 'Escape' && !this.inert) {
event.preventDefault()
this.hide()
}
},
arrowKeys: function(e) {
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
e.preventDefault()
const currentIndex = this.promptButtons.findIndex((cur) => {
return cur === e.target
})
const direction = (e.key === 'ArrowLeft') ? -1 : 1
this.focusItem(parseInt(currentIndex) + direction)
const currentIndex = this.promptButtons.findIndex((cur) => {
return cur === e.target
})

// Only react if a button was focused when the arrow key was pressed
if (currentIndex === -1) {
return
}

e.preventDefault()

const direction = (e.key === 'ArrowLeft') ? -1 : 1
this.focusItem(parseInt(currentIndex) + direction)
},

...mapActions([
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/components/ft-prompt/ft-prompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
ref="openPrompt"
class="prompt"
tabindex="-1"
:inert="inert"
@click="handleHide"
@keydown.enter="handleHide"
@keydown.left.right.capture="arrowKeys"
>
<ft-card
ref="promptCard"
class="promptCard"
:class="{ autosize, [theme]: true }"
role="dialog"
Expand All @@ -33,7 +36,6 @@
<ft-flex-box>
<ft-button
v-for="(option, index) in optionNames"
:id="'prompt-' + sanitizedLabel + '-' + index"
:key="index"
:label="option"
:text-color="optionButtonTextColor(index)"
Expand Down