Skip to content

Commit b04b133

Browse files
committed
Escape key binding fixes ...
- Bindings are created and destroyed when necessary on Panes and Stacks - Not on filters and columns since the panes and stacks handle them - Add a binding to the favorite creator when its shown, and destroy when its hidden
1 parent f0a23d6 commit b04b133

5 files changed

Lines changed: 27 additions & 28 deletions

File tree

resources/js/components/FavoriteCreator.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<popper v-if="isNotYetFavorited" ref="popper" @show="highlight" trigger="click" :append-to-body="true" :options="{ placement: 'bottom' }">
3+
<popper v-if="isNotYetFavorited" ref="popper" @show="shown" @hide="hidden" trigger="click" :append-to-body="true" :options="{ placement: 'bottom' }">
44

55
<div class="card p-0 shadow-lg z-top">
66
<div class="flex justify-between text-center">
@@ -46,6 +46,7 @@ export default {
4646
name: document.title.replace(' ‹ Statamic', ''),
4747
currentUrl: this.$config.get('urlPath').substr(this.$config.get('cpRoot').length+1),
4848
showingPinTab: true,
49+
escBinding: null,
4950
}
5051
},
5152
@@ -69,6 +70,15 @@ export default {
6970
},
7071
7172
methods: {
73+
shown() {
74+
this.escBinding = this.$keys.bindGlobal('esc', e => this.$refs.popper.doClose());
75+
this.highlight();
76+
},
77+
78+
hidden() {
79+
this.escBinding.destroy();
80+
},
81+
7282
highlight() {
7383
setTimeout(() => this.$refs.fave.select(), 20);
7484
},
@@ -116,12 +126,6 @@ export default {
116126
}
117127
});
118128
},
119-
},
120-
121-
mounted() {
122-
this.$keys.bindGlobal(['esc'], e => {
123-
this.$refs.popper.doClose();
124-
});
125129
}
126130
}
127131
</script>

resources/js/components/data-list/ColumnPicker.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ export default {
130130
this.$toast.error(__('Something went wrong'));
131131
});
132132
}
133-
},
134-
135-
created() {
136-
this.$keys.bind('esc', this.dismiss)
137-
},
133+
}
138134
}
139135
</script>

resources/js/components/data-list/Filters.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ export default {
124124
this.$toast.error(__('Something went wrong'));
125125
});
126126
}
127-
},
128-
129-
created() {
130-
this.$keys.bind('esc', this.dismiss)
131-
},
127+
}
132128
133129
}
134130
</script>

resources/js/components/panes/Pane.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@
1313
<script>
1414
export default {
1515
16+
data() {
17+
return {
18+
escBinding: null,
19+
}
20+
},
21+
1622
created() {
1723
this.$panes.open(this);
24+
this.escBinding = this.$keys.bindGlobal('esc', this.close);
1825
},
1926
2027
destroyed() {
2128
this.$panes.close(this);
29+
this.escBinding.destroy();
2230
},
2331
2432
methods: {
@@ -27,12 +35,6 @@ export default {
2735
this.$emit('closed');
2836
},
2937
30-
},
31-
32-
mounted() {
33-
this.$keys.bindGlobal(['esc'], e => {
34-
this.close();
35-
});
3638
}
3739
3840
}

resources/js/components/stacks/Stack.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export default {
4646
depth: null,
4747
portal: null,
4848
visible: false,
49-
isHovering: false
49+
isHovering: false,
50+
escBinding: null,
5051
}
5152
},
5253
@@ -92,12 +93,14 @@ export default {
9293
9394
this.$events.$on(`stacks.${this.depth}.hit-area-mouseenter`, () => this.isHovering = true);
9495
this.$events.$on(`stacks.${this.depth}.hit-area-mouseout`, () => this.isHovering = false);
96+
this.escBinding = this.$keys.bindGlobal('esc', this.close);
9597
},
9698
9799
destroyed() {
98100
this.$stacks.remove(this);
99101
this.$events.$off(`stacks.${this.depth}.hit-area-mouseenter`);
100102
this.$events.$off(`stacks.${this.depth}.hit-area-mouseout`);
103+
this.escBinding.destroy();
101104
},
102105
103106
methods: {
@@ -133,11 +136,9 @@ export default {
133136
134137
mounted() {
135138
this.visible = true;
139+
},
140+
136141
137-
this.$keys.bindGlobal(['esc'], e => {
138-
this.close();
139-
});
140-
}
141142
142143
}
143144
</script>

0 commit comments

Comments
 (0)