Skip to content

Commit 4a8ce2c

Browse files
authored
feat(modal): Add Bootstrap V4 anticipated verticaly centered modal (#1246)
* feat(modal): Add Bootstrap V4 anticipated verticaly centered modal Vertically centered modals will be coming in Bootstrap V4.beta.3 This adds a new prop `centered` which renders the modal centered vertically. twbs/bootstrap#24510 Note vertically centered modals are **not** suited for tall content modals, as there is a potential for the header (or top part of the modal) to become inaccessible). They are better suited to one or two line content (i.e. confirmation dialogs). The custom CSS in modal.vue can be removed once V4.beta.3 (or later) arrives * update modal docs * SpellCheck :scroll:
1 parent a3a9aa5 commit 4a8ce2c

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

docs/components/modal/README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,36 @@ breakpoints to avoid horizontal scrollbars on narrower viewports. Valid optional
270270

271271
<!-- modal-sizes.vue -->
272272
```
273+
274+
275+
## Vertically centering
276+
Vertically center your modal in the viewport by setting the `center` prop.
277+
278+
```html
279+
<div>
280+
<b-btn v-b-modal.modal-center>Launch centered modal</b-btn>
281+
282+
<!-- Modal Component -->
283+
<b-modal id="modal-center" center title="Bootstrap-Vue">
284+
<p class="my-4">Vertically centered modal!</p>
285+
</b-modal>
286+
</div>
287+
288+
<!-- modal-center-v.vue -->
289+
```
290+
291+
**Warning:** Vertically centered modals are not suited for when the content is tall.
292+
They are best suited when the content is only one or two lines, such as Yes/No or
293+
OK/Cancel confirmation dialogs. When the resultant modal is taller than the viewport,
294+
the modal header (and parts of the top of the modal content) will become inaccessible.
295+
This issue becomes more prevalent on smaller screens.
296+
297+
273298
## Using the grid
274299
Utilize the Bootstrap grid system within a modal by nesting `<b-container fluid>` within
275-
the modal-body. Then, use the normal grid system `<b-row>` and `<b-col>` as you would
276-
anywhere else.
300+
the modal-body. Then, use the normal grid system `<b-row>` (or `<b-form-row>`) and `<b-col>`
301+
as you would anywhere else.
302+
277303

278304
## Tooltips and popovers
279305
Tooltips and popovers can be placed within modals as needed. When modals are closed, any tooltips
@@ -302,6 +328,7 @@ they are appended by specifying a container ID (refer to tooltip and popover doc
302328
<!-- modal-popover.vue -->
303329
```
304330

331+
305332
## Variants
306333
Control the header, footer, and body background and text variants by setting the
307334
`header-bg-variant`, `header-text-variant`, `body-bg-variant`, `body-text-variant`,
@@ -375,6 +402,7 @@ export default {
375402
<!-- modal-variant-1.vue -->
376403
```
377404

405+
378406
## Lazy loading
379407
Modal will always render its HTML markup in the document at the location that
380408
the `<b-modal>` component is placed (even if it is not shown). You can hide
@@ -475,6 +503,7 @@ event's `target` property:
475503
**Note:** If the `<b-modal>` has the `return-focus` prop set, then the element specified
476504
via the event will be ignored.
477505

506+
478507
## Keyboard Navigation
479508

480509
When tabbing through elements within a `<b-modal>`, if focus attempts to leave the modal into the document,
@@ -483,4 +512,5 @@ it will be brought back into the modal.
483512
In some circumstances, you may need to disable the enforce focus feature. You can do this
484513
by setting the prop `no-enforce-focus`.
485514

515+
486516
## Component Reference

lib/components/modal.vue

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@
8282
</div>
8383
</template>
8484

85+
<style>
86+
/*
87+
This can be removed once Bootstrap V4.beta.3 is released
88+
https://github.com/twbs/bootstrap/pull/24510
89+
Vertically centered modals are not suited to tall content (the header gets cut off)
90+
*/
91+
.modal-dialog-centered {
92+
display: flex;
93+
align-items: center;
94+
height: 100%;
95+
margin-top: 0 !important;
96+
margin-bottom: 0 !important;
97+
}
98+
.modal-dialog-centered .modal-content {
99+
width: 100%;
100+
}
101+
</style>
102+
85103
<script>
86104
import bBtn from './button';
87105
import bBtnClose from './button-close';
@@ -136,6 +154,10 @@
136154
type: String,
137155
default: 'md'
138156
},
157+
centered: {
158+
type: Boolean,
159+
default: false
160+
},
139161
buttonSize: {
140162
type: String,
141163
default: ''
@@ -267,7 +289,8 @@
267289
return [
268290
'modal-dialog',
269291
{
270-
[`modal-${this.size}`]: Boolean(this.size)
292+
[`modal-${this.size}`]: Boolean(this.size),
293+
'modal-dialog-centered': this.centered
271294
}
272295
];
273296
},

0 commit comments

Comments
 (0)