Merge remote-tracking branch 'origin/main' into sync-80-125

This commit is contained in:
Liam DeBeasi
2023-12-05 09:12:24 -05:00
24 changed files with 310 additions and 113 deletions

15
.github/labeler.yml vendored
View File

@ -6,16 +6,17 @@
# https://github.com/actions/labeler # https://github.com/actions/labeler
'package: core': 'package: core':
- core/**/* - changed-files:
- any-glob-to-any-file: ['core/**/*']
'package: angular': 'package: angular':
- packages/angular/**/* - changed-files:
- packages/angular-*/**/* - any-glob-to-any-file: ['packages/angular/**/*', 'packages/angular-*/**/*']
'package: react': 'package: react':
- packages/react/**/* - changed-files:
- packages/react-*/**/* - any-glob-to-any-file: ['packages/react/**/*', 'packages/react-*/**/*']
'package: vue': 'package: vue':
- packages/vue/**/* - changed-files:
- packages/vue-*/**/* - any-glob-to-any-file: ['packages/vue/**/*', 'packages/vue-*/**/*']

View File

@ -13,7 +13,7 @@ jobs:
triage: triage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/labeler@main - uses: actions/labeler@v5
with: with:
repo-token: "${{ secrets.GITHUB_TOKEN }}" repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true sync-labels: true

14
core/package-lock.json generated
View File

@ -9,7 +9,7 @@
"version": "7.5.7", "version": "7.5.7",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@stencil/core": "^4.8.0", "@stencil/core": "^4.8.1",
"ionicons": "^7.2.1", "ionicons": "^7.2.1",
"tslib": "^2.1.0" "tslib": "^2.1.0"
}, },
@ -1825,9 +1825,9 @@
} }
}, },
"node_modules/@stencil/core": { "node_modules/@stencil/core": {
"version": "4.8.0", "version": "4.8.1",
"resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.8.0.tgz", "resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.8.1.tgz",
"integrity": "sha512-iNEaMiEt9oFZXSjZ7qkdlBpPTzWzBgWM7go8nI8a7V6ZOkmdVhhT0xGQD7OY13v5ZuDoIw5IsGvbIAGefhIhhQ==", "integrity": "sha512-KG1H10j24rlyxIqOI4CG8/h9T7ObTv7giW2H3u1qXV4KKrLykDOpMcLzpqNXqL2Fki3s1QvHyl/oaRvi5waWVw==",
"bin": { "bin": {
"stencil": "bin/stencil" "stencil": "bin/stencil"
}, },
@ -12184,9 +12184,9 @@
"requires": {} "requires": {}
}, },
"@stencil/core": { "@stencil/core": {
"version": "4.8.0", "version": "4.8.1",
"resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.8.0.tgz", "resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.8.1.tgz",
"integrity": "sha512-iNEaMiEt9oFZXSjZ7qkdlBpPTzWzBgWM7go8nI8a7V6ZOkmdVhhT0xGQD7OY13v5ZuDoIw5IsGvbIAGefhIhhQ==" "integrity": "sha512-KG1H10j24rlyxIqOI4CG8/h9T7ObTv7giW2H3u1qXV4KKrLykDOpMcLzpqNXqL2Fki3s1QvHyl/oaRvi5waWVw=="
}, },
"@stencil/react-output-target": { "@stencil/react-output-target": {
"version": "0.5.3", "version": "0.5.3",

View File

@ -31,7 +31,7 @@
"loader/" "loader/"
], ],
"dependencies": { "dependencies": {
"@stencil/core": "^4.8.0", "@stencil/core": "^4.8.1",
"ionicons": "^7.2.1", "ionicons": "^7.2.1",
"tslib": "^2.1.0" "tslib": "^2.1.0"
}, },

View File

@ -1162,7 +1162,7 @@ export namespace Components {
*/ */
"autocorrect": 'on' | 'off'; "autocorrect": 'on' | 'off';
/** /**
* This Boolean attribute lets you specify that a form control should have input focus when the page loads. * Sets the [`autofocus` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) on the native input element. This may not be sufficient for the element to be focused on page load. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
"autofocus": boolean; "autofocus": boolean;
/** /**
@ -1274,7 +1274,7 @@ export namespace Components {
*/ */
"required": boolean; "required": boolean;
/** /**
* Sets focus on the native `input` in `ion-input`. Use this method instead of the global `input.focus()`. Developers who wish to focus an input when a page enters should call `setFocus()` in the `ionViewDidEnter()` lifecycle method. Developers who wish to focus an input when an overlay is presented should call `setFocus` after `didPresent` has resolved. * Sets focus on the native `input` in `ion-input`. Use this method instead of the global `input.focus()`. Developers who wish to focus an input when a page enters should call `setFocus()` in the `ionViewDidEnter()` lifecycle method. Developers who wish to focus an input when an overlay is presented should call `setFocus` after `didPresent` has resolved. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
"setFocus": () => Promise<void>; "setFocus": () => Promise<void>;
/** /**
@ -2601,7 +2601,7 @@ export namespace Components {
*/ */
"searchIcon"?: string; "searchIcon"?: string;
/** /**
* Sets focus on the native `input` in `ion-searchbar`. Use this method instead of the global `input.focus()`. Developers who wish to focus an input when a page enters should call `setFocus()` in the `ionViewDidEnter()` lifecycle method. Developers who wish to focus an input when an overlay is presented should call `setFocus` after `didPresent` has resolved. * Sets focus on the native `input` in `ion-searchbar`. Use this method instead of the global `input.focus()`. Developers who wish to focus an input when a page enters should call `setFocus()` in the `ionViewDidEnter()` lifecycle method. Developers who wish to focus an input when an overlay is presented should call `setFocus` after `didPresent` has resolved. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
"setFocus": () => Promise<void>; "setFocus": () => Promise<void>;
/** /**
@ -2950,7 +2950,7 @@ export namespace Components {
*/ */
"autocapitalize": string; "autocapitalize": string;
/** /**
* This Boolean attribute lets you specify that a form control should have input focus when the page loads. * Sets the [`autofocus` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) on the native input element. This may not be sufficient for the element to be focused on page load. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
"autofocus": boolean; "autofocus": boolean;
/** /**
@ -3050,7 +3050,7 @@ export namespace Components {
*/ */
"rows"?: number; "rows"?: number;
/** /**
* Sets focus on the native `textarea` in `ion-textarea`. Use this method instead of the global `textarea.focus()`. * Sets focus on the native `textarea` in `ion-textarea`. Use this method instead of the global `textarea.focus()`. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
"setFocus": () => Promise<void>; "setFocus": () => Promise<void>;
/** /**
@ -5854,7 +5854,7 @@ declare namespace LocalJSX {
*/ */
"autocorrect"?: 'on' | 'off'; "autocorrect"?: 'on' | 'off';
/** /**
* This Boolean attribute lets you specify that a form control should have input focus when the page loads. * Sets the [`autofocus` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) on the native input element. This may not be sufficient for the element to be focused on page load. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
"autofocus"?: boolean; "autofocus"?: boolean;
/** /**
@ -7699,7 +7699,7 @@ declare namespace LocalJSX {
*/ */
"autocapitalize"?: string; "autocapitalize"?: string;
/** /**
* This Boolean attribute lets you specify that a form control should have input focus when the page loads. * Sets the [`autofocus` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) on the native input element. This may not be sufficient for the element to be focused on page load. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
"autofocus"?: boolean; "autofocus"?: boolean;
/** /**

View File

@ -337,6 +337,17 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
if (this.isOpen === true) { if (this.isOpen === true) {
raf(() => this.present()); raf(() => this.present());
} }
/**
* When binding values in frameworks such as Angular
* it is possible for the value to be set after the Web Component
* initializes but before the value watcher is set up in Stencil.
* As a result, the watcher callback may not be fired.
* We work around this by manually calling the watcher
* callback when the component has loaded and the watcher
* is configured.
*/
this.triggerChanged();
} }
render() { render() {

View File

@ -376,6 +376,17 @@ export class Alert implements ComponentInterface, OverlayInterface {
if (this.isOpen === true) { if (this.isOpen === true) {
raf(() => this.present()); raf(() => this.present());
} }
/**
* When binding values in frameworks such as Angular
* it is possible for the value to be set after the Web Component
* initializes but before the value watcher is set up in Stencil.
* As a result, the watcher callback may not be fired.
* We work around this by manually calling the watcher
* callback when the component has loaded and the watcher
* is configured.
*/
this.triggerChanged();
} }
/** /**

View File

@ -95,7 +95,9 @@ export class Input implements ComponentInterface {
@Prop() autocorrect: 'on' | 'off' = 'off'; @Prop() autocorrect: 'on' | 'off' = 'off';
/** /**
* This Boolean attribute lets you specify that a form control should have input focus when the page loads. * Sets the [`autofocus` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) on the native input element.
*
* This may not be sufficient for the element to be focused on page load. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
@Prop() autofocus = false; @Prop() autofocus = false;
@ -424,6 +426,8 @@ export class Input implements ComponentInterface {
* *
* Developers who wish to focus an input when an overlay is presented * Developers who wish to focus an input when an overlay is presented
* should call `setFocus` after `didPresent` has resolved. * should call `setFocus` after `didPresent` has resolved.
*
* See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
@Method() @Method()
async setFocus() { async setFocus() {

View File

@ -225,6 +225,17 @@ export class Loading implements ComponentInterface, OverlayInterface {
if (this.isOpen === true) { if (this.isOpen === true) {
raf(() => this.present()); raf(() => this.present());
} }
/**
* When binding values in frameworks such as Angular
* it is possible for the value to be set after the Web Component
* initializes but before the value watcher is set up in Stencil.
* As a result, the watcher callback may not be fired.
* We work around this by manually calling the watcher
* callback when the component has loaded and the watcher
* is configured.
*/
this.triggerChanged();
} }
disconnectedCallback() { disconnectedCallback() {

View File

@ -368,6 +368,17 @@ export class Modal implements ComponentInterface, OverlayInterface {
raf(() => this.present()); raf(() => this.present());
} }
this.breakpointsChanged(this.breakpoints); this.breakpointsChanged(this.breakpoints);
/**
* When binding values in frameworks such as Angular
* it is possible for the value to be set after the Web Component
* initializes but before the value watcher is set up in Stencil.
* As a result, the watcher callback may not be fired.
* We work around this by manually calling the watcher
* callback when the component has loaded and the watcher
* is configured.
*/
this.triggerChanged();
} }
/** /**

View File

@ -209,6 +209,17 @@ export class Picker implements ComponentInterface, OverlayInterface {
if (this.isOpen === true) { if (this.isOpen === true) {
raf(() => this.present()); raf(() => this.present());
} }
/**
* When binding values in frameworks such as Angular
* it is possible for the value to be set after the Web Component
* initializes but before the value watcher is set up in Stencil.
* As a result, the watcher callback may not be fired.
* We work around this by manually calling the watcher
* callback when the component has loaded and the watcher
* is configured.
*/
this.triggerChanged();
} }
/** /**

View File

@ -370,6 +370,17 @@ export class Popover implements ComponentInterface, PopoverInterface {
this.dismiss(undefined, undefined, false); this.dismiss(undefined, undefined, false);
}); });
} }
/**
* When binding values in frameworks such as Angular
* it is possible for the value to be set after the Web Component
* initializes but before the value watcher is set up in Stencil.
* As a result, the watcher callback may not be fired.
* We work around this by manually calling the watcher
* callback when the component has loaded and the watcher
* is configured.
*/
this.configureTriggerInteraction();
} }
/** /**

View File

@ -257,6 +257,8 @@ export class Searchbar implements ComponentInterface {
* *
* Developers who wish to focus an input when an overlay is presented * Developers who wish to focus an input when an overlay is presented
* should call `setFocus` after `didPresent` has resolved. * should call `setFocus` after `didPresent` has resolved.
*
* See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
@Method() @Method()
async setFocus() { async setFocus() {

View File

@ -93,7 +93,9 @@ export class Textarea implements ComponentInterface {
@Prop() autocapitalize = 'none'; @Prop() autocapitalize = 'none';
/** /**
* This Boolean attribute lets you specify that a form control should have input focus when the page loads. * Sets the [`autofocus` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) on the native input element.
*
* This may not be sufficient for the element to be focused on page load. See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
@Prop() autofocus = false; @Prop() autofocus = false;
@ -372,6 +374,8 @@ export class Textarea implements ComponentInterface {
/** /**
* Sets focus on the native `textarea` in `ion-textarea`. Use this method instead of the global * Sets focus on the native `textarea` in `ion-textarea`. Use this method instead of the global
* `textarea.focus()`. * `textarea.focus()`.
*
* See [managing focus](/docs/developing/managing-focus) for more information.
*/ */
@Method() @Method()
async setFocus() { async setFocus() {

View File

@ -288,6 +288,17 @@ export class Toast implements ComponentInterface, OverlayInterface {
if (this.isOpen === true) { if (this.isOpen === true) {
raf(() => this.present()); raf(() => this.present());
} }
/**
* When binding values in frameworks such as Angular
* it is possible for the value to be set after the Web Component
* initializes but before the value watcher is set up in Stencil.
* As a result, the watcher callback may not be fired.
* We work around this by manually calling the watcher
* callback when the component has loaded and the watcher
* is configured.
*/
this.triggerChanged();
} }
/** /**

View File

@ -1,7 +1,8 @@
import type { RouteInfo, ViewItem } from '@ionic/react'; import type { RouteInfo, ViewItem } from '@ionic/react';
import { IonRoute, ViewLifeCycleManager, ViewStacks, generateId } from '@ionic/react'; import { IonRoute, ViewLifeCycleManager, ViewStacks, generateId } from '@ionic/react';
import React from 'react'; import React from 'react';
import { matchPath } from 'react-router';
import { matchPath } from './utils/matchPath';
export class ReactRouterViewStack extends ViewStacks { export class ReactRouterViewStack extends ViewStacks {
constructor() { constructor() {
@ -23,21 +24,16 @@ export class ReactRouterViewStack extends ViewStacks {
ionRoute: false, ionRoute: false,
}; };
const matchProps = {
exact: reactElement.props.exact,
path: reactElement.props.path || reactElement.props.from,
component: reactElement.props.component,
};
const match = matchPath(routeInfo.pathname, matchProps);
if (reactElement.type === IonRoute) { if (reactElement.type === IonRoute) {
viewItem.ionRoute = true; viewItem.ionRoute = true;
viewItem.disableIonPageManagement = reactElement.props.disableIonPageManagement; viewItem.disableIonPageManagement = reactElement.props.disableIonPageManagement;
} }
viewItem.routeData = { viewItem.routeData = {
match, match: matchPath({
pathname: routeInfo.pathname,
componentProps: reactElement.props,
}),
childProps: reactElement.props, childProps: reactElement.props,
}; };
@ -106,7 +102,7 @@ export class ReactRouterViewStack extends ViewStacks {
} }
findLeavingViewItemByRouteInfo(routeInfo: RouteInfo, outletId?: string, mustBeIonRoute = true) { findLeavingViewItemByRouteInfo(routeInfo: RouteInfo, outletId?: string, mustBeIonRoute = true) {
const { viewItem } = this.findViewItemByPath(routeInfo.lastPathname!, outletId, false, mustBeIonRoute); const { viewItem } = this.findViewItemByPath(routeInfo.lastPathname!, outletId, mustBeIonRoute);
return viewItem; return viewItem;
} }
@ -115,7 +111,10 @@ export class ReactRouterViewStack extends ViewStacks {
return viewItem; return viewItem;
} }
private findViewItemByPath(pathname: string, outletId?: string, forceExact?: boolean, mustBeIonRoute?: boolean) { /**
* Returns the matching view item and the match result for a given pathname.
*/
private findViewItemByPath(pathname: string, outletId?: string, mustBeIonRoute?: boolean) {
let viewItem: ViewItem | undefined; let viewItem: ViewItem | undefined;
let match: ReturnType<typeof matchPath> | undefined; let match: ReturnType<typeof matchPath> | undefined;
let viewStack: ViewItem[]; let viewStack: ViewItem[];
@ -140,16 +139,24 @@ export class ReactRouterViewStack extends ViewStacks {
if (mustBeIonRoute && !v.ionRoute) { if (mustBeIonRoute && !v.ionRoute) {
return false; return false;
} }
const matchProps = {
exact: forceExact ? true : v.routeData.childProps.exact, match = matchPath({
path: v.routeData.childProps.path || v.routeData.childProps.from, pathname,
component: v.routeData.childProps.component, componentProps: v.routeData.childProps,
}; });
const myMatch = matchPath(pathname, matchProps);
if (myMatch) { if (match) {
viewItem = v; /**
match = myMatch; * Even though we have a match from react-router, we do not know if the match
return true; * is for this specific view item.
*
* To validate this, we need to check if the path and url match the view item's route data.
*/
const hasParameter = match.path.includes(':');
if (!hasParameter || (hasParameter && match.url === v.routeData?.match?.url)) {
viewItem = v;
return true;
}
} }
return false; return false;
} }
@ -171,13 +178,9 @@ export class ReactRouterViewStack extends ViewStacks {
} }
} }
function matchComponent(node: React.ReactElement, pathname: string, forceExact?: boolean) { function matchComponent(node: React.ReactElement, pathname: string) {
const matchProps = { return matchPath({
exact: forceExact ? true : node.props.exact, pathname,
path: node.props.path || node.props.from, componentProps: node.props,
component: node.props.component, });
};
const match = matchPath(pathname, matchProps);
return match;
} }

View File

@ -1,9 +1,9 @@
import type { RouteInfo, StackContextState, ViewItem } from '@ionic/react'; import type { RouteInfo, StackContextState, ViewItem } from '@ionic/react';
import { RouteManagerContext, StackContext, generateId, getConfig } from '@ionic/react'; import { RouteManagerContext, StackContext, generateId, getConfig } from '@ionic/react';
import React from 'react'; import React from 'react';
import { matchPath } from 'react-router-dom';
import { clonePageElement } from './clonePageElement'; import { clonePageElement } from './clonePageElement';
import { matchPath } from './utils/matchPath';
// TODO(FW-2959): types // TODO(FW-2959): types
@ -433,12 +433,10 @@ export default StackManager;
function matchRoute(node: React.ReactNode, routeInfo: RouteInfo) { function matchRoute(node: React.ReactNode, routeInfo: RouteInfo) {
let matchedNode: React.ReactNode; let matchedNode: React.ReactNode;
React.Children.forEach(node as React.ReactElement, (child: React.ReactElement) => { React.Children.forEach(node as React.ReactElement, (child: React.ReactElement) => {
const matchProps = { const match = matchPath({
exact: child.props.exact, pathname: routeInfo.pathname,
path: child.props.path || child.props.from, componentProps: child.props,
component: child.props.component, });
};
const match = matchPath(routeInfo.pathname, matchProps);
if (match) { if (match) {
matchedNode = child; matchedNode = child;
} }
@ -459,12 +457,11 @@ function matchRoute(node: React.ReactNode, routeInfo: RouteInfo) {
} }
function matchComponent(node: React.ReactElement, pathname: string, forceExact?: boolean) { function matchComponent(node: React.ReactElement, pathname: string, forceExact?: boolean) {
const matchProps = { return matchPath({
exact: forceExact ? true : node.props.exact, pathname,
path: node.props.path || node.props.from, componentProps: {
component: node.props.component, ...node.props,
}; exact: forceExact,
const match = matchPath(pathname, matchProps); },
});
return match;
} }

View File

@ -0,0 +1,47 @@
import { matchPath as reactRouterMatchPath } from 'react-router';
interface MatchPathOptions {
/**
* The pathname to match against.
*/
pathname: string;
/**
* The props to match against, they are identical to the matching props `Route` accepts.
*/
componentProps: {
path?: string;
from?: string;
component?: any;
exact?: boolean;
};
}
/**
* @see https://v5.reactrouter.com/web/api/matchPath
*/
export const matchPath = ({
pathname,
componentProps,
}: MatchPathOptions): false | ReturnType<typeof reactRouterMatchPath> => {
const { exact, component } = componentProps;
const path = componentProps.path || componentProps.from;
/***
* The props to match against, they are identical
* to the matching props `Route` accepts. It could also be a string
* or an array of strings as shortcut for `{ path }`.
*/
const matchProps = {
exact,
path,
component,
};
const match = reactRouterMatchPath(pathname, matchProps);
if (!match) {
return false;
}
return match;
};

View File

@ -24,10 +24,6 @@ const Details: React.FC<DetailsProps> = () => {
return () => console.log('Home Details unmount'); return () => console.log('Home Details unmount');
}, []); }, []);
// useIonViewWillEnter(() => {
// console.log('IVWE Details')
// })
const nextId = parseInt(id, 10) + 1; const nextId = parseInt(id, 10) + 1;
return ( return (
@ -58,6 +54,9 @@ const Details: React.FC<DetailsProps> = () => {
<IonButton routerLink={`/routing/tabs/settings/details/1`}> <IonButton routerLink={`/routing/tabs/settings/details/1`}>
<IonLabel>Go to Settings Details 1</IonLabel> <IonLabel>Go to Settings Details 1</IonLabel>
</IonButton> </IonButton>
<br />
<br />
<input data-testid="details-input" />
</IonContent> </IonContent>
</IonPage> </IonPage>
); );

View File

@ -309,6 +309,41 @@ describe('Routing Tests', () => {
cy.ionPageDoesNotExist('home-details-page-1'); cy.ionPageDoesNotExist('home-details-page-1');
cy.ionPageVisible('home-page'); cy.ionPageVisible('home-page');
}); });
it('should mount new view item instances of parameterized routes', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home/details/1`);
cy.get('div.ion-page[data-pageid=home-details-page-1]')
.get('[data-testid="details-input"]')
.should('have.value', '');
cy.get('div.ion-page[data-pageid=home-details-page-1] [data-testid="details-input"]').type('1');
cy.ionNav('ion-button', 'Go to Details 2');
cy.ionPageVisible('home-details-page-2');
cy.get('div.ion-page[data-pageid=home-details-page-2] [data-testid="details-input"]').should('have.value', '');
cy.get('div.ion-page[data-pageid=home-details-page-2] [data-testid="details-input"]').type('2');
cy.ionNav('ion-button', 'Go to Details 3');
cy.ionPageVisible('home-details-page-3');
cy.get('div.ion-page[data-pageid=home-details-page-3] [data-testid="details-input"]').should('have.value', '');
cy.get('div.ion-page[data-pageid=home-details-page-3] [data-testid="details-input"]').type('3');
cy.ionBackClick('home-details-page-3');
cy.ionPageVisible('home-details-page-2');
cy.get('div.ion-page[data-pageid=home-details-page-2] [data-testid="details-input"]').should('have.value', '2');
cy.ionBackClick('home-details-page-2');
cy.ionPageVisible('home-details-page-1');
cy.get('div.ion-page[data-pageid=home-details-page-1] [data-testid="details-input"]').should('have.value', '1');
});
/* /*
Tests to add: Tests to add:
Test that lifecycle events fire Test that lifecycle events fire

View File

@ -4,7 +4,7 @@ import { defineComponent, h, shallowRef } from "vue";
import { VueDelegate } from "../framework-delegate"; import { VueDelegate } from "../framework-delegate";
export const IonNav = /*@__PURE__*/ defineComponent(() => { export const IonNav = /*@__PURE__*/ defineComponent((props) => {
defineCustomElement(); defineCustomElement();
const views = shallowRef([]); const views = shallowRef([]);
@ -19,8 +19,39 @@ export const IonNav = /*@__PURE__*/ defineComponent(() => {
const delegate = VueDelegate(addView, removeView); const delegate = VueDelegate(addView, removeView);
return () => { return () => {
return h("ion-nav", { delegate }, views.value); return h("ion-nav", { ...props, delegate }, views.value);
}; };
}); });
IonNav.name = "IonNav"; IonNav.name = "IonNav";
/**
* The default values follow what is defined at
* https://ionicframework.com/docs/api/nav#properties
* otherwise the default values on the Web Component
* may be overridden. For example, if the default animated value
* is not `true` below, then Vue would default the prop to `false`
* which would override the Web Component default of `true`.
*/
IonNav.props = {
animated: {
type: Boolean,
default: true,
},
animation: {
type: Function,
default: undefined,
},
root: {
type: [Function, Object, String],
default: undefined,
},
rootParams: {
type: Object,
default: undefined,
},
swipeGesture: {
type: Boolean,
default: undefined,
},
};

View File

@ -1,16 +1,12 @@
<template> <template>
<ion-nav :root="NavRoot"></ion-nav> <ion-nav :root="NavRoot" :root-params="rootParams"></ion-nav>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent } from 'vue'; import { IonNav } from "@ionic/vue";
import { IonNav } from '@ionic/vue'; import NavRoot from "@/components/NavRoot.vue";
import NavRoot from '@/components/NavRoot.vue';
export default defineComponent({ const rootParams = {
components: { IonNav }, message: "Hello World!",
setup() { };
return { NavRoot }
}
});
</script> </script>

View File

@ -8,11 +8,14 @@
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content class="ion-padding"> <ion-content class="ion-padding">
<ion-button expand="block" @click="pushPage" id="push-nav-child">Go to Nav Child</ion-button> <div id="nav-root-params">Message: {{ message }}</div>
<ion-button expand="block" @click="pushPage" id="push-nav-child"
>Go to Nav Child</ion-button
>
</ion-content> </ion-content>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { import {
IonButtons, IonButtons,
IonButton, IonButton,
@ -20,28 +23,20 @@ import {
IonHeader, IonHeader,
IonTitle, IonTitle,
IonToolbar, IonToolbar,
modalController modalController,
} from '@ionic/vue'; } from "@ionic/vue";
import { defineComponent } from 'vue'; import NavChild from "@/components/NavChild.vue";
import NavChild from '@/components/NavChild.vue';
export default defineComponent({ defineProps<{
components: { message: string;
IonButtons, }>();
IonButton,
IonContent, function pushPage() {
IonHeader, const ionNav = document.querySelector("ion-nav") as any;
IonTitle, ionNav.push(NavChild, { title: "Custom Title" });
IonToolbar }
},
methods: { async function dismiss() {
pushPage: function() { await modalController.dismiss();
const ionNav = document.querySelector('ion-nav') as any; }
ionNav.push(NavChild, { title: 'Custom Title' });
},
dismiss: async function() {
await modalController.dismiss();
}
}
})
</script> </script>

View File

@ -10,4 +10,10 @@ describe('Navigation', () => {
cy.get('#nav-child-content').should('have.text', 'Custom Title'); cy.get('#nav-child-content').should('have.text', 'Custom Title');
}); });
it('nav should support kebab-case root-params', () => {
cy.get('#open-nav-modal').click();
cy.get('#nav-root-params').should('have.text', 'Message: Hello World!');
});
}); });