Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Automatically focus modal when mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasHirt committed Jun 2, 2020
1 parent 6d8b153 commit 51d04d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/modal-focus
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Automatically focus modal

When the modal is mounted, it receives automatically a focus.
The focus is sent directly to the modal itself so skipping the wrapping div which works only as a background.

https://github.com/owncloud/owncloud-design-system/pull/781
8 changes: 7 additions & 1 deletion src/elements/OcModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="oc-modal-background">
<div :class="$_ocModal_classes">
<div :class="$_ocModal_classes" tabindex="0" ref="$_ocModal">
<div class="oc-modal-title">
<oc-icon
v-if="icon"
Expand Down Expand Up @@ -217,6 +217,12 @@ export default {
}
},
mounted() {
this.$nextTick(() => {
this.$refs.$_ocModal.focus()
})
},
methods: {
$_ocModal_buttonCancel_click() {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/elements/__snapshots__/OcModal.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`OcModal displays input 1`] = `
<div class="oc-modal-background">
<div class="oc-modal oc-modal-info">
<div tabindex="0" class="oc-modal oc-modal-info">
<div class="oc-modal-title">
<!----> <span>Create new folder</span></div>
<div class="oc-modal-body">
Expand All @@ -18,7 +18,7 @@ exports[`OcModal displays input 1`] = `

exports[`OcModal hides icon if not specified 1`] = `
<div class="oc-modal-background">
<div class="oc-modal oc-modal-info">
<div tabindex="0" class="oc-modal oc-modal-info">
<div class="oc-modal-title">
<!----> <span>Example title</span></div>
<div class="oc-modal-body">
Expand All @@ -34,7 +34,7 @@ exports[`OcModal hides icon if not specified 1`] = `

exports[`OcModal matches snapshot 1`] = `
<div class="oc-modal-background">
<div class="oc-modal oc-modal-info">
<div tabindex="0" class="oc-modal oc-modal-info">
<div class="oc-modal-title">
<oc-icon-stub name="info" arialabel="icon" type="span" size="small" variation="system"></oc-icon-stub> <span>Example title</span>
</div>
Expand All @@ -51,7 +51,7 @@ exports[`OcModal matches snapshot 1`] = `

exports[`OcModal overrides props message with slot 1`] = `
<div class="oc-modal-background">
<div class="oc-modal oc-modal-info">
<div tabindex="0" class="oc-modal oc-modal-info">
<div class="oc-modal-title">
<!----> <span>Example title</span></div>
<div class="oc-modal-body">
Expand Down
4 changes: 4 additions & 0 deletions src/styles/theme/oc-modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
border-radius: 8px;
overflow: hidden;

&:focus {
outline: none;
}

&-background {
position: fixed;
top: 0;
Expand Down

0 comments on commit 51d04d3

Please sign in to comment.