File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 6666</template >
6767
6868<script setup lang="ts">
69- import { ref , onMounted , computed } from " vue" ;
69+ import { ref , onMounted , computed , onUnmounted } from " vue" ;
7070import { messageProps , messageEmits } from " ./message" ;
7171import JwIcon from " @/lib/icon/index.vue" ;
7272import { Info24Filled } from " @vicons/fluent" ;
@@ -101,9 +101,26 @@ function close() {
101101 visible .value = false ;
102102}
103103
104+ function keydown({ code }: KeyboardEvent ) {
105+ if (code === " Escape" ) {
106+ // press esc to close the message
107+ if (visible .value ) {
108+ close ();
109+ }
110+ } else {
111+ startTimer (); // resume timer
112+ }
113+ }
114+
104115onMounted (() => {
105116 startTimer ();
106117 visible .value = true ;
118+
119+ document .addEventListener (" keydown" , keydown );
120+ });
121+
122+ onUnmounted (() => {
123+ document .removeEventListener (" keydown" , keydown );
107124});
108125 </script >
109126<script lang="ts">
You can’t perform that action at this time.
0 commit comments