Skip to content

Commit 82bb571

Browse files
committed
set ssr prop default to true, set attach prop default to false
1 parent 40def8a commit 82bb571

File tree

7 files changed

+23
-43
lines changed

7 files changed

+23
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default {
8282

8383
| Name | Type | Required | Default | Description |
8484
| --- | --- | --- | --- | --- |
85-
| ssr | Boolean | --- | false | use v-if(true) or v-show(false) |
85+
| ssr | Boolean | --- | true | use v-show(true) or v-if(false) |
8686
| classes | [String, Object, Array] | --- | '' | custom class names for Modal container element |
8787
| contentClass | [String, Object, Array] | --- | '' | custom class names for Modal content element |
8888
| lockScroll | Boolean | --- | true | whether scroll of body is disabled while Dialog is displayed |
@@ -92,7 +92,7 @@ export default {
9292
| overlayClass | String | --- | '' | Add classes to the overlay element. |
9393
| transition | String | --- | 'vfm' | CSS transition applied to the modal window. |
9494
| overlayTransition | String | --- | 'vfm' | CSS transition applied to the overlay (background). |
95-
| attach | any | --- | 'body' | Specifies which DOM element that this component should detach to. Set `false` will disabled this feature. String can be any valid querySelector and Object can be any valid Node. This will attach to the <body> element by default. |
95+
| attach | any | --- | false | Specifies which DOM element that this component should detach to. String can be any valid querySelector and Object can be any valid Node. |
9696

9797
### Slots
9898

docs/components/global/BaseExample.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
:hide-overlay="false"
1212
:click-to-close="true"
1313
:prevent-click="false"
14-
attach="body"
14+
:attach="false"
1515
:z-index="1000"
1616
>
1717
<span class="text-2xl mb-2">Hello, world!</span>

docs/components/global/BaseExampleAttach.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<div
1515
id="attach"
1616
class="relative flex justify-center items-center w-full h-64 dark:bg-gray-700 border dark:border-gray-700"
17-
></div>
17+
>
18+
#attach
19+
</div>
1820
</div>
1921
</template>
2022

docs/components/global/BaseExampleAttachFalse.vue

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/content/en/examples.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ category: Getting Start
1313
<base-example-prevent-click></base-example-prevent-click>
1414
<base-example-stackable></base-example-stackable>
1515
<base-example-scroll></base-example-scroll>
16-
<base-example-attach-false></base-example-attach-false>
1716
<base-example-attach></base-example-attach>
1817
</div>

docs/content/en/properties.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: Getting Start
88
## `ssr`
99

1010
- Type: `Boolean`
11-
- Default: `false`
11+
- Default: `true`
1212

1313
Use `v-if` (false) or `v-show` (true) to display the modal.
1414

@@ -79,14 +79,12 @@ The click event will not be blocked by overlay.
7979
## `attach`
8080

8181
- Type: `Any`
82-
- Default: `'body'`
82+
- Default: `false`
8383

8484
Specifies which DOM element that this component should detach to.
8585

86-
1. By default, the modal will be attached to the `<body>` element.
87-
2. Set `false` will disabled this feature.
88-
3. String can be any valid `querySelector`
89-
4. Object can be any valid `Node`.
86+
1. String can be any valid `querySelector`.
87+
2. Object can be any valid `Node`.
9088

9189
## `zIndex`
9290

@@ -113,7 +111,7 @@ Set `z-index` to both of the modal container and overlay elements.
113111
:hide-overlay="false"
114112
:click-to-close="true"
115113
:prevent-click="false"
116-
attach="body"
114+
:attach="false"
117115
:z-index="1000"
118116
>
119117
<span class="text-2xl mb-2">Hello, world!</span>

lib/VueFinalModal.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
:style="{ zIndex }"
1313
class="vfm__overlay"
1414
:class="[
15-
{ 'vfm__overlay--attach': attach !== 'body' },
15+
{ 'vfm__overlay--attach': attach !== false },
1616
{ 'vfm__overlay--prevent-click': preventClick },
1717
overlayClass
1818
]"
@@ -31,7 +31,7 @@
3131
class="vfm__container"
3232
:class="[
3333
{
34-
'vfm__container--attach': attach !== 'body',
34+
'vfm__container--attach': attach !== false,
3535
'vfm__container--prevent-click': preventClick
3636
},
3737
classes
@@ -67,19 +67,27 @@ const TransitionState = {
6767
Leaving: 'leavng'
6868
}
6969
70+
function validateAttachTarget(val) {
71+
const type = typeof val
72+
73+
if (type === 'boolean' || type === 'string') return true
74+
75+
return val.nodeType === Node.ELEMENT_NODE
76+
}
77+
7078
export default {
7179
name: 'VueFinalModal',
7280
props: {
7381
value: { type: Boolean, default: false },
74-
ssr: { type: Boolean, default: false },
82+
ssr: { type: Boolean, default: true },
7583
classes: { type: [String, Object, Array], default: '' },
7684
contentClass: { type: [String, Object, Array], default: '' },
7785
lockScroll: { type: Boolean, default: true },
7886
hideOverlay: { type: Boolean, default: false },
7987
clickToClose: { type: Boolean, default: true },
8088
preventClick: { type: Boolean, default: false },
8189
overlayClass: { type: String, default: '' },
82-
attach: { type: null, default: 'body' },
90+
attach: { type: null, default: false, validator: validateAttachTarget },
8391
transition: { type: String, default: 'vfm' },
8492
overlayTransition: { type: String, default: 'vfm' },
8593
zIndex: { type: [String, Number], default: 1000 }

0 commit comments

Comments
 (0)