Skip to content

Commit 9050a9f

Browse files
authored
fix(vue): respect keepContentsMounted if passed as attribute (#28167)
Issue number: resolves #28165 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> The overlay implementation in Vue only checks for truthy `keepContentsMounted` values. When setting this prop as an attribute, the value of it is `''` which is falsy. As a result, content does not get mounted. One of Vue's ESLint rules states that this should be supported: https://eslint.vuejs.org/rules/prefer-true-attribute-shorthand.html Part of the issue may also be that Vue does not know the type of this property and so it assume "any": > The shorthand form is not always equivalent! If a prop accepts multiple types, but Boolean is not the first one, a shorthand prop won't pass true. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - The overlay wrapper now checks for `''` values. If `keepContentsMounted === ''` then the inner contents will be mounted because this means the prop is being set using the attribute shorthand. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev build: `7.3.5-dev.11694621267.1e5f63c2`
1 parent a5f14e3 commit 9050a9f

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

packages/vue/src/vue-component-lib/overlays.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ export const defineOverlayContainer = <Props extends object>(name: string, defin
177177
return h(
178178
name,
179179
{ ...restOfProps, ref: elementRef },
180-
(isOpen.value || restOfProps.keepContentsMounted) ? renderChildren() : undefined
180+
181+
/**
182+
* When binding keepContentsMounted as an attribute
183+
* i.e. <ion-modal keep-contents-mounted></ion-modal>
184+
* the value of the prop will be the empty string which is
185+
* why we still call renderChildren() in that case.
186+
*/
187+
(isOpen.value || restOfProps.keepContentsMounted || restOfProps.keepContentsMounted === '') ? renderChildren() : undefined
181188
)
182189
}
183190
});

packages/vue/test/base/src/views/OverlaysKeepContentsMounted.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
<ion-button id="open-auto-mount-popover">Open Auto Mount Popover</ion-button>
1616

17+
<ion-button id="open-auto-mount-modal-attribute">Open Auto Mount Modal (Attribute)</ion-button>
18+
19+
<ion-button id="open-auto-mount-modal-attribute-false">Open Auto Mount Modal (Attribute False)</ion-button>
20+
1721
<br /><br />
1822

1923
<ion-modal
@@ -31,6 +35,22 @@
3135
>
3236
<PopoverContent :title="overlayProps.title"></PopoverContent>
3337
</ion-popover>
38+
39+
<ion-modal
40+
id="auto-mount-modal-attribute"
41+
keep-contents-mounted
42+
trigger="open-auto-mount-modal-attribute"
43+
>
44+
<ModalContent :title="overlayProps.title"></ModalContent>
45+
</ion-modal>
46+
47+
<ion-modal
48+
id="auto-mount-modal-attribute-false"
49+
keep-contents-mounted="false"
50+
trigger="open-auto-mount-modal-attribute-false"
51+
>
52+
<ModalContent :title="overlayProps.title"></ModalContent>
53+
</ion-modal>
3454
</ion-content>
3555
</ion-page>
3656
</template>

packages/vue/test/base/tests/e2e/specs/overlays-keep-contents-mounted.cy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ describe('overlays - keepContentsMounted', () => {
2525

2626
cy.get('ion-modal#auto-mount-modal ion-content').should('exist');
2727
});
28+
29+
it('should mount content if passed as attribute', () => {
30+
cy.get('ion-modal#auto-mount-modal-attribute ion-content').should('exist');
31+
});
32+
33+
it('should not mount content if passed as attribute with a value of false', () => {
34+
cy.get('ion-modal#auto-mount-modal-attribute-false ion-content').should('not.exist');
35+
});
2836
})
2937
describe('popover', () => {
3038
it('should not mount component if false', () => {

0 commit comments

Comments
 (0)