diff --git a/core/src/components/popover/popover.scss b/core/src/components/popover/popover.scss index 1fd11ddf896..c61cdec8d71 100644 --- a/core/src/components/popover/popover.scss +++ b/core/src/components/popover/popover.scss @@ -93,6 +93,8 @@ min-height: var(--min-height); max-height: var(--max-height); + outline: none; + background: var(--background); box-shadow: var(--box-shadow); diff --git a/core/src/components/popover/popover.tsx b/core/src/components/popover/popover.tsx index 68006141a33..70195e38c88 100644 --- a/core/src/components/popover/popover.tsx +++ b/core/src/components/popover/popover.tsx @@ -2,7 +2,8 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core'; import { Component, Element, Event, Host, Method, Prop, State, Watch, h } from '@stencil/core'; import { focusFirstDescendant } from '@utils/focus-trap'; import { CoreDelegate, attachComponent, detachComponent } from '@utils/framework-delegate'; -import { addEventListener, raf, hasLazyBuild } from '@utils/helpers'; +import { addEventListener, raf, hasLazyBuild, inheritAttributes } from '@utils/helpers'; +import type { Attributes } from '@utils/helpers'; import { createLockController } from '@utils/lock-controller'; import { printIonWarning } from '@utils/logging'; import { OverlayFocusBoundary } from '@utils/overlay-focus-boundary'; @@ -71,6 +72,7 @@ export class Popover implements ComponentInterface, PopoverInterface { private headerResizeObserver?: ResizeObserver; private inline = false; + private inheritedAttributes: Attributes = {}; private workingDelegate?: FrameworkDelegate; private focusDescendantOnPresent = false; @@ -389,7 +391,21 @@ export class Popover implements ComponentInterface, PopoverInterface { } componentWillLoad() { - const { el } = this; + const { el, htmlAttributes } = this; + + const attributesToInherit = ['aria-label', 'role']; + this.inheritedAttributes = inheritAttributes(el, attributesToInherit); + if (htmlAttributes !== undefined) { + attributesToInherit.forEach((attribute) => { + if (htmlAttributes[attribute]) { + this.inheritedAttributes = { + ...this.inheritedAttributes, + [attribute]: htmlAttributes[attribute], + }; + delete htmlAttributes[attribute]; + } + }); + } const popoverId = this.htmlAttributes?.id ?? setOverlayId(el); this.parentPopover = el.closest(`ion-popover:not(#${popoverId})`) as HTMLIonPopoverElement | null; @@ -772,7 +788,6 @@ export class Popover implements ComponentInterface, PopoverInterface { return ( this.dismiss() : undefined}> {enableArrow &&
} -
+
diff --git a/core/src/components/popover/test/basic/popover.e2e.ts b/core/src/components/popover/test/basic/popover.e2e.ts index 44f0ee7dd06..d9832b9697c 100644 --- a/core/src/components/popover/test/basic/popover.e2e.ts +++ b/core/src/components/popover/test/basic/popover.e2e.ts @@ -220,7 +220,12 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => */ await expect(popover).toBeFocused(); - await page.keyboard.press(tabKey); + /** + * Focus the textarea directly instead of tabbing to it. In Firefox, + * Tab from the focused popover content stops on the scrollable + * ion-textarea first, the same as it does for a native dialog. + */ + await innerNativeTextarea.focus(); await expect(innerNativeTextarea).toBeFocused(); diff --git a/core/src/components/popover/test/popover-attributes.spec.tsx b/core/src/components/popover/test/popover-attributes.spec.tsx new file mode 100644 index 00000000000..6fed4966c9c --- /dev/null +++ b/core/src/components/popover/test/popover-attributes.spec.tsx @@ -0,0 +1,52 @@ +import { h } from '@stencil/core'; +import { newSpecPage } from '@stencil/core/testing'; + +import { Popover } from '../popover'; + +// Fixes https://github.com/ionic-team/ionic-framework/issues/31823 +describe('popover: attributes', () => { + it('should set the dialog role and aria-modal on the content', async () => { + const page = await newSpecPage({ + components: [Popover], + template: () => , + }); + + const popover = page.body.querySelector('ion-popover')!; + const content = popover.shadowRoot!.querySelector('[part="content"]')!; + + expect(content.getAttribute('role')).toBe('dialog'); + expect(content.getAttribute('aria-modal')).toBe('true'); + expect(popover.hasAttribute('aria-modal')).toBe(false); + }); + + it('should inherit attributes', async () => { + const page = await newSpecPage({ + components: [Popover], + template: () => , + }); + + const popover = page.body.querySelector('ion-popover')!; + const content = popover.shadowRoot!.querySelector('[part="content"]')!; + + expect(content.getAttribute('aria-label')).toBe('my label'); + expect(content.getAttribute('role')).toBe('alertdialog'); + }); + + it('should inherit attributes when set via htmlAttributes', async () => { + const page = await newSpecPage({ + components: [Popover], + template: () => ( + + ), + }); + + const popover = page.body.querySelector('ion-popover')!; + const content = popover.shadowRoot!.querySelector('[part="content"]')!; + + expect(content.getAttribute('aria-label')).toBe('my label'); + expect(content.getAttribute('role')).toBe('alertdialog'); + + expect(popover.hasAttribute('aria-label')).toBe(false); + expect(popover.hasAttribute('role')).toBe(false); + }); +});