diff --git a/core/src/components.d.ts b/core/src/components.d.ts index 42fff08fdfe..78bbf19d1c6 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -3309,16 +3309,16 @@ export namespace Components { interface IonTabs { "getRouteId": () => Promise; /** - * Get the currently selected tab. This method is only available for vanilla JavaScript projects. The Angular, React, and Vue implementations of tabs are coupled to each framework's router. + * Get the currently selected tab. In React and Vue, this method only works when tabs are used without a router outlet. */ "getSelected": () => Promise; /** - * Get a specific tab by the value of its `tab` property or an element reference. This method is only available for vanilla JavaScript projects. The Angular, React, and Vue implementations of tabs are coupled to each framework's router. - * @param tab The tab instance to select. If passed a string, it should be the value of the tab's `tab` property. + * Get a specific tab by the value of its `tab` property or an element reference. In React and Vue, this method only works when tabs are used without a router outlet. + * @param tab The tab instance to get. If passed a string, it should be the value of the tab's `tab` property. */ "getTab": (tab: string | HTMLIonTabElement) => Promise; /** - * Select a tab by the value of its `tab` property or an element reference. This method is only available for vanilla JavaScript projects. The Angular, React, and Vue implementations of tabs are coupled to each framework's router. + * Select a tab by the value of its `tab` property or an element reference. In React and Vue, this method only works when tabs are used without a router outlet. With a router outlet, tabs are coupled to the framework's router, so navigate with the router instead. * @param tab The tab instance to select. If passed a string, it should be the value of the tab's `tab` property. */ "select": (tab: string | HTMLIonTabElement) => Promise; diff --git a/core/src/components/tabs/tabs.tsx b/core/src/components/tabs/tabs.tsx index 20f4d84d136..9881ae6ae13 100644 --- a/core/src/components/tabs/tabs.tsx +++ b/core/src/components/tabs/tabs.tsx @@ -95,7 +95,10 @@ export class Tabs implements NavOutlet { } /** - * Select a tab by the value of its `tab` property or an element reference. This method is only available for vanilla JavaScript projects. The Angular, React, and Vue implementations of tabs are coupled to each framework's router. + * Select a tab by the value of its `tab` property or an element reference. + * + * In React and Vue, this method only works when tabs are used without a router outlet. With a router outlet, + * tabs are coupled to the framework's router, so navigate with the router instead. * * @param tab The tab instance to select. If passed a string, it should be the value of the tab's `tab` property. */ @@ -113,9 +116,11 @@ export class Tabs implements NavOutlet { } /** - * Get a specific tab by the value of its `tab` property or an element reference. This method is only available for vanilla JavaScript projects. The Angular, React, and Vue implementations of tabs are coupled to each framework's router. + * Get a specific tab by the value of its `tab` property or an element reference. * - * @param tab The tab instance to select. If passed a string, it should be the value of the tab's `tab` property. + * In React and Vue, this method only works when tabs are used without a router outlet. + * + * @param tab The tab instance to get. If passed a string, it should be the value of the tab's `tab` property. */ @Method() async getTab(tab: string | HTMLIonTabElement): Promise { @@ -123,7 +128,9 @@ export class Tabs implements NavOutlet { } /** - * Get the currently selected tab. This method is only available for vanilla JavaScript projects. The Angular, React, and Vue implementations of tabs are coupled to each framework's router. + * Get the currently selected tab. + * + * In React and Vue, this method only works when tabs are used without a router outlet. */ @Method() getSelected(): Promise { @@ -233,7 +240,7 @@ const getTab = (tabs: HTMLIonTabElement[], tab: string | HTMLIonTabElement): HTM const tabEl = typeof tab === 'string' ? tabs.find((t) => t.tab === tab) : tab; if (!tabEl) { - printIonError(`[ion-tabs] - Tab with id: "${tabEl}" does not exist`); + printIonError(`[ion-tabs] - Tab with id: "${tab}" does not exist`); } return tabEl; }; diff --git a/core/src/components/tabs/test/tabs.spec.ts b/core/src/components/tabs/test/tabs.spec.ts new file mode 100644 index 00000000000..bddb2d0caee --- /dev/null +++ b/core/src/components/tabs/test/tabs.spec.ts @@ -0,0 +1,27 @@ +import { newSpecPage } from '@stencil/core/testing'; + +import { Tab } from '../../tab/tab'; +import { Tabs } from '../tabs'; + +describe('tabs: getTab', () => { + it('should name the requested tab when it does not exist', async () => { + const page = await newSpecPage({ + components: [Tabs, Tab], + html: ` + + Home + + `, + }); + + const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {}); + + const tabs = page.body.querySelector('ion-tabs')!; + const tab = await tabs.getTab('settings'); + + expect(tab).toBeUndefined(); + expect(consoleError).toHaveBeenCalledWith('[Ionic Error]: [ion-tabs] - Tab with id: "settings" does not exist'); + + consoleError.mockRestore(); + }); +});