Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move close button within modal boundaries #2738

Merged
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
3 changes: 3 additions & 0 deletions l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ msgstr ""
msgid "Close"
msgstr ""

msgid "Close modal"
msgstr ""

msgid "Close navigation"
msgstr ""

Expand Down
33 changes: 32 additions & 1 deletion src/components/Modal/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
</Actions>

<!-- Close modal -->
<Actions v-if="canClose" class="header-close">
<Actions v-if="canClose && !closeButtonContained" class="header-close">
<ActionButton @click="close">
<template #icon>
<Close :size="iconSize" title="" decorative />
Expand Down Expand Up @@ -207,6 +207,16 @@

<!-- Content -->
<div class="modal-container">
<!-- Close modal -->
<ButtonVue v-if="canClose && closeButtonContained"
type="tertiary"
class="modal-container__close"
:aria-label="closeButtonAriaLabel"
@click="close">
<template #icon>
<Close :size="20" title="" decorative />
</template>
</ButtonVue>
<!-- @slot Modal content to render -->
<slot />
</div>
Expand Down Expand Up @@ -241,6 +251,7 @@ import Tooltip from '../../directives/Tooltip/index.js'
import l10n from '../../mixins/l10n.js'
import Timer from '../../utils/Timer.js'
import { t } from '../../l10n.js'
import ButtonVue from '../../components/Button/index.js'

import ChevronLeft from 'vue-material-design-icons/ChevronLeft'
import ChevronRight from 'vue-material-design-icons/ChevronRight'
Expand All @@ -261,6 +272,7 @@ export default {
Close,
Pause,
Play,
ButtonVue,
},

directives: {
Expand Down Expand Up @@ -367,6 +379,15 @@ export default {
type: String,
default: 'body',
},

/**
* Pass in false if you want the modal 'close' button to be displayed
* outside the modal boundaries, in the top right corner of the window
*/
closeButtonContained: {
type: Boolean,
default: true,
},
},

data() {
Expand Down Expand Up @@ -395,6 +416,10 @@ export default {
'--icon-size': this.iconSize + 'px',
}
},

closeButtonAriaLabel() {
return t('Close modal')
},
},

watch: {
Expand Down Expand Up @@ -776,13 +801,19 @@ export default {

/* Content */
.modal-container {
position: relative;
display: block;
overflow: auto; // avoids unecessary hacks if the content should be bigger than the modal
padding: 0;
transition: transform 300ms ease;
border-radius: var(--border-radius-large);
background-color: var(--color-main-background);
box-shadow: 0 0 40px rgba(0, 0, 0, .2);
&__close {
position: absolute;
top: 4px;
right: 4px;
}
}

// Sizing
Expand Down