@@ -5,57 +5,14 @@ support a number of use cases from user notification to completely custom conten
5
5
feature a handful of helpful sub-components, sizes, variants, accessibility, and more.
6
6
7
7
``` html
8
- <template >
9
- <div >
10
- <b-btn v-b-modal.modal1 >Launch demo modal</b-btn >
11
- <!-- Main UI -->
12
- <div class =" mt-3 mb-3" >
13
- Submitted Names:
14
- <ul >
15
- <li v-for =" n in names" >{{n}}</li >
16
- </ul >
17
- </div >
18
- <!-- Modal Component -->
19
- <b-modal id =" modal1"
20
- ref =" modal1"
21
- title =" Submit your name"
22
- @ok =" handleOk"
23
- @shown =" clearName" >
24
- <form @submit.stop.prevent =" handleSubmit" >
25
- <b-form-input type =" text"
26
- placeholder =" Enter your name"
27
- v-model =" name" ></b-form-input >
28
- </form >
29
- </b-modal >
30
- </div >
31
- </template >
8
+ <div >
9
+ <b-btn v-b-modal.modal1 >Launch demo modal</b-btn >
32
10
33
- <script >
34
- export default {
35
- data: {
36
- name: ' ' ,
37
- names: []
38
- },
39
- methods: {
40
- clearName () {
41
- this .name = ' ' ;
42
- },
43
- handleOk (e ) {
44
- e .preventDefault ();
45
- if (! this .name ) {
46
- alert (' Please enter your name' );
47
- } else {
48
- this .handleSubmit ()
49
- }
50
- },
51
- handleSubmit () {
52
- this .names .push (this .name );
53
- this .clearName ();
54
- this .$refs .modal1 .hide ();
55
- }
56
- }
57
- }
58
- </script >
11
+ <!-- Modal Component -->
12
+ <b-modal id =" modal1" title =" Bootstrap-Vue" >
13
+ <p clas =" my-4" >Hello from modal!</p >
14
+ </b-modal >
15
+ </div >
59
16
60
17
<!-- modal-1.vue -->
61
18
```
@@ -88,16 +45,20 @@ There are several methods that you can employ to toggle the visibility of `<b-mo
88
45
Other elements can easily show modals using the ` v-b-modal ` directive.
89
46
90
47
``` html
91
- <!-- Using modifiers -->
92
- <b-btn v-b-modal.myModal >Show Modal</b-btn >
48
+ <div >
49
+ <!-- Using modifiers -->
50
+ <b-btn v-b-modal.myModal >Show Modal</b-btn >
93
51
94
- <!-- Using value -->
95
- <b-btn v-b-modal =" 'myMmodal'" >Show Modal</b-btn >
52
+ <!-- Using value -->
53
+ <b-btn v-b-modal =" 'myMmodal'" >Show Modal</b-btn >
96
54
97
- <!-- the modal -->
98
- <b-modal id =" myMmodal" >
55
+ <!-- the modal -->
56
+ <b-modal id =" myMmodal" >
99
57
Hello From My Modal!
100
- </b-modal >
58
+ </b-modal >
59
+ </div >
60
+
61
+ <!-- modal-directive-1.vue -->
101
62
```
102
63
103
64
Focus will automatically be returned to the trigger element once the modal closes.
@@ -133,7 +94,7 @@ export default {
133
94
}
134
95
</script >
135
96
136
- <!-- modal-2 .vue -->
97
+ <!-- modal-methods-1 .vue -->
137
98
```
138
99
139
100
The ` hide() ` method accepts an optional argument. See section ** Prevent Closing**
@@ -162,7 +123,7 @@ export default {
162
123
}
163
124
</script >
164
125
165
- <!-- modal-3 .vue -->
126
+ <!-- modal-v-model-1 .vue -->
166
127
```
167
128
168
129
When using the ` v-model ` property, do not use the ` visible ` property at the same time.
@@ -173,7 +134,7 @@ When using the `v-model` property, do not use the `visible` property at the same
173
134
You can emit ` bv::show::modal ` and ` bv::hide::modal ` event on ` $root ` with the first
174
135
argument set to the modal's id. An optional second argument can specify the element
175
136
to return focus to once the modal is closed. The second argument can be a CSS selector,
176
- and element reference, or a component reference.
137
+ an element reference, or a component reference.
177
138
178
139
``` html
179
140
<b-button @click =" showModal" ref =" btnShow" >
@@ -209,29 +170,60 @@ the `preventDefault()` method of the event object passed to your `ok` (**OK** bu
209
170
` cancel ` (** Cancel** button) and ` hide ` event handlers.
210
171
211
172
``` html
212
- <b-modal id =" modalPrevent" @hide =" save" >
213
- Hello From Modal!
214
- <b-alert variant =" danger" :show =" message ? true : false" >
215
- {{ message }}
216
- </b-alert >
217
- </b-modal >
218
- ```
173
+ <template >
174
+ <div >
175
+ <b-btn v-b-modal.modalPrevent >Launch demo modal</b-btn >
176
+ <!-- Main UI -->
177
+ <div class =" mt-3 mb-3" >
178
+ Submitted Names:
179
+ <ul >
180
+ <li v-for =" n in names" >{{n}}</li >
181
+ </ul >
182
+ </div >
183
+ <!-- Modal Component -->
184
+ <b-modal id =" modalPrevent"
185
+ ref =" modal"
186
+ title =" Submit your name"
187
+ @ok =" handleOk"
188
+ @shown =" clearName" >
189
+ <form @submit.stop.prevent =" handleSubmit" >
190
+ <b-form-input type =" text"
191
+ placeholder =" Enter your name"
192
+ v-model =" name" ></b-form-input >
193
+ </form >
194
+ </b-modal >
195
+ </div >
196
+ </template >
219
197
220
- ``` js
221
- data: {
222
- saved: false ,
223
- message: null
224
- },
225
- methods: {
226
- save (e ) {
227
- if (! this .saved ) {
228
- this .message = ' Please save your work' ;
229
- e .preventDefault ();
230
- } else {
231
- this .message = null ;
232
- }
198
+ <script >
199
+ export default {
200
+ data: {
201
+ name: ' ' ,
202
+ names: []
203
+ },
204
+ methods: {
205
+ clearName () {
206
+ this .name = ' ' ;
207
+ },
208
+ handleOk (evt ) {
209
+ // Prevent modal from closing
210
+ evt .preventDefault ();
211
+ if (! this .name ) {
212
+ alert (' Please enter your name' );
213
+ } else {
214
+ this .handleSubmit ()
215
+ }
216
+ },
217
+ handleSubmit () {
218
+ this .names .push (this .name );
219
+ this .clearName ();
220
+ this .$refs .modal .hide ();
233
221
}
222
+ }
234
223
}
224
+ </script >
225
+
226
+ <!-- modal-prevent-1.vue -->
235
227
```
236
228
237
229
** Note** : events ` ok ` and ` cancel ` are emitted by modal's built in ** OK** and ** Cancel**
@@ -252,8 +244,8 @@ The `ok`, `cancel`, and `hide` event object contains several properties and meth
252
244
You can set the value of ` trigger ` by passing an argument to the component's
253
245
` hide() ` method for advanced control.
254
246
255
- ** Note:** ` ok ` and ` cancel ` events will be only emitted when the argument to ` hide() ` is strictly ` ok `
256
- or ` cancel ` respectively. The argument passed to ` hide() ` will be placed into the
247
+ ** Note:** ` ok ` and ` cancel ` events will be only emitted when the argument to ` hide() ` is strictly ` 'ok' `
248
+ or ` ' cancel' ` respectively. The argument passed to ` hide() ` will be placed into the
257
249
` trigger ` property of the event object.
258
250
259
251
@@ -318,6 +310,69 @@ variants such as `danger`, `warning`, `info`, `success`, `dark`, `light`, etc.
318
310
The variants for the bottom border of the header and top border of the footer can be
319
311
controlled by the ` header-border-variant ` and ` footer-border-variant ` props respectively.
320
312
313
+ <template >
314
+ <b-btn @click ="show=true" variant="primary">Show Modal</b-btn >
315
+ <b-modal v-model="show"
316
+ title="Modal Variants"
317
+ : header-bg-variant ="headerBgVariant"
318
+ : header-text-variant ="headerTextVariant"
319
+ : body-bg-variant ="bodyBgVariant"
320
+ : body-text-variant ="bodyTextVariant"
321
+ : footer-bg-variant ="footerBgVariant"
322
+ : footer-text-variant ="footerTextVariant">
323
+ <b-container fluid >
324
+ <b-row class =" mb-1 text-center " >
325
+ <b-col cols =" 3 " > </b-col >
326
+ <b-col >Background</b-col >
327
+ <b-col >Text</b-col >
328
+ </b-row >
329
+ <b-row class =" mb-1 " >
330
+ <b-col cols =" 3 " >Header</b-col >
331
+ <b-col ><b-form-select :options =" variants " v-model =" headerBgVariant " /></b-col >
332
+ <b-col ><b-form-select :options =" variants " v-model =" headerTextVariant " /></b-col >
333
+ </b-row >
334
+ <b-row class =" mb-1 " >
335
+ <b-col cols =" 3 " >Body</b-col >
336
+ <b-col ><b-form-select :options =" variants " v-model =" bodyBgVariant " /></b-col >
337
+ <b-col ><b-form-select :options =" variants " v-model =" bodyTextVariant " /></b-col >
338
+ </b-row >
339
+ <b-row >
340
+ <b-col cols =" 3 " >Footer</b-col >
341
+ <b-col ><b-form-select :options =" variants " v-model =" footerBgVariant " /></b-col >
342
+ <b-col ><b-form-select :options =" variants " v-model =" footerTextVariant " /></b-col >
343
+ </b-row >
344
+ </b-container >
345
+ <div slot =" modal-footer " class =" w-100 " >
346
+ <p class =" float-left " >Modal Footer Content</p >
347
+ <b-btn size="sm" class="float-right" variant="primary" @click ="show=false">
348
+ Close
349
+ </b-btn >
350
+ </div >
351
+ </b-modal >
352
+ </template >
353
+
354
+ <script >
355
+ export default {
356
+ data () {
357
+ return {
358
+ show: false ,
359
+ variants: [
360
+ ' primary' ,' secondary' ,' success' ,' warning' ,' danger' ,' info' ,' light' ,' dark'
361
+ ],
362
+ headerBgVariant: ' dark' ,
363
+ headerTextVariant: ' light' ,
364
+ bodyBgVariant: ' light' ,
365
+ bodyTextVariant: ' dark' ,
366
+ footerBgVariant: ' warning' ,
367
+ footerTextVariant: ' dark'
368
+ };
369
+ }
370
+ };
371
+ </script >
372
+
373
+ <!-- modal-variant-1.vue -->
374
+
375
+
321
376
## Accessibility
322
377
323
378
` <b-modal> ` provides several accessibility features, including auto focus, return
@@ -337,23 +392,22 @@ an element already has focus within the `<b-modal>`.
337
392
338
393
``` html
339
394
<b-modal @shown =" focusMyElement" >
340
- <b-button >I Don't Have Focus</b-button >
341
- <br >
342
- <b-form-input type =" text" ></b-form-input >
343
- <br >
344
- <!-- element to gain focus when modal is opened -->
345
- <b-form-input ref =" focusThis" type =" text" ></b-form-input >
346
- <br >
347
- <b-form-input type =" text" ></b-form-input >
348
- <br >
395
+ <b-button >I Don't Have Focus</b-button >
396
+ <br >
397
+ <b-form-input type =" text" ></b-form-input >
398
+ <br >
399
+ <!-- element to gain focus when modal is opened -->
400
+ <b-form-input ref =" focusThis" type =" text" ></b-form-input >
401
+ <br >
402
+ <b-form-input type =" text" ></b-form-input >
349
403
</b-modal >
350
404
```
351
405
352
406
``` js
353
407
methods: {
354
- focusMyElement (e ) {
355
- this .$refs .focusThis .focus ();
356
- }
408
+ focusMyElement (e ) {
409
+ this .$refs .focusThis .focus ();
410
+ }
357
411
}
358
412
```
359
413
@@ -387,19 +441,19 @@ been specified via the `return-focus` prop.
387
441
388
442
#### Specify Return Focus via Event
389
443
390
- When using the ` show::modal ` event (emitted on ` $root ` ), you can specify a second argument
444
+ When using the ` bv:: show::modal` event (emitted on ` $root ` ), you can specify a second argument
391
445
which is the element to return focus to. This argument accepts the same types
392
446
as the ` return-focus ` prop.
393
447
394
448
``` js
395
- this .$root .$emit (' show::modal' , ' modal1' , ' #focusThisOnClose' );
449
+ this .$root .$emit (' bv:: show::modal' , ' modal1' , ' #focusThisOnClose' );
396
450
```
397
451
398
452
* Tip:* if using a click event (or similar) to trigger modal to open, pass the
399
453
event's ` target ` property:
400
454
401
455
``` html
402
- <b-btn @click =" $root.$emit.('show::modal', 'modal1', $event.target)" >
456
+ <b-btn @click =" $root.$emit.('bv:: show::modal', 'modal1', $event.target)" >
403
457
Open Modal
404
458
</b-btn >
405
459
```
0 commit comments