2828 >
2929 <CloseIcon />
3030 </button >
31- <div class =" modal-content" >
31+ <div class =" modal-content" ref = " content " >
3232 <slot />
3333 </div >
3434 </div >
@@ -137,7 +137,7 @@ export default {
137137 },
138138 mounted () {
139139 this .focusTrapInstance = new FocusTrap ();
140- document .addEventListener (' keydown' , this .onEscapeClick );
140+ document .addEventListener (' keydown' , this .onKeydown );
141141 // add listeners for dynamic themes
142142 if (this .isThemeDynamic ) {
143143 const matchMedia = window .matchMedia (' (prefers-color-scheme: dark)' );
@@ -155,7 +155,7 @@ export default {
155155 if (this .isVisible ) {
156156 scrollLock .unlockScroll (this .$refs .container );
157157 }
158- document .removeEventListener (' keydown' , this .onEscapeClick );
158+ document .removeEventListener (' keydown' , this .onKeydown );
159159 this .focusTrapInstance .destroy ();
160160 },
161161 methods: {
@@ -190,6 +190,14 @@ export default {
190190 closeModal () {
191191 this .isVisible = false ;
192192 },
193+ /**
194+ * Select all modal's content
195+ */
196+ selectContent () {
197+ window .getSelection ().selectAllChildren (
198+ this .$refs .content ,
199+ );
200+ },
193201 /**
194202 * Closes the modal when clicking on the backdrop
195203 */
@@ -198,12 +206,23 @@ export default {
198206 },
199207 /**
200208 * Handle the keydown body event listener.
201- * Used to close the modal on `Escape` click.
209+ * Used to:
210+ * - Overwrite cmd+a and ctrl+a behaviour to select modal content only
211+ * - Close the modal on `Escape` click.
202212 * @param {KeyboardEvent} params
203213 * @param {String} params.key
204214 */
205- onEscapeClick ({ key }) {
206- if (! this .isVisible || key !== ' Escape' ) return ;
215+ onKeydown (event ) {
216+ const {
217+ metaKey = false , ctrlKey = false , key,
218+ } = event ;
219+
220+ if (! this .isVisible ) return ;
221+ if (key === ' a' && (metaKey || ctrlKey)) {
222+ event .preventDefault ();
223+ this .selectContent ();
224+ }
225+ if (key !== ' Escape' ) return ;
207226 this .closeModal ();
208227 },
209228 /**
@@ -269,12 +288,8 @@ $modal-close-color: light-color(figure-gray-tertiary) !default;
269288 & -standard {
270289 padding : 20px ;
271290
272- & .modal-with-close .container {
273- padding-top : 80px ;
274- }
275-
276291 .container {
277- padding : 50 px ;
292+ padding : 60 px ;
278293 border-radius : $big-border-radius ;
279294 @include prefers-dark {
280295 background : rgb (29 , 29 , 31 );
0 commit comments