diff --git a/change/@microsoft-fast-foundation-903a969b-3de3-4090-974a-3423344c571c.json b/change/@microsoft-fast-foundation-903a969b-3de3-4090-974a-3423344c571c.json new file mode 100644 index 00000000000..2e5757701c4 --- /dev/null +++ b/change/@microsoft-fast-foundation-903a969b-3de3-4090-974a-3423344c571c.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Fix focus issues with toolbar", + "packageName": "@microsoft/fast-foundation", + "email": "20542556+mollykreis@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/web-components/fast-foundation/docs/api-report.md b/packages/web-components/fast-foundation/docs/api-report.md index f3e0d3e5186..08571043560 100644 --- a/packages/web-components/fast-foundation/docs/api-report.md +++ b/packages/web-components/fast-foundation/docs/api-report.md @@ -2620,8 +2620,6 @@ export class Toolbar extends FoundationElement { childItems: Element[]; // (undocumented) protected childItemsChanged(prev: undefined | Element[], next: Element[]): void; - // @internal - clickHandler(e: MouseEvent): boolean | void; // @internal (undocumented) connectedCallback(): void; // @internal @@ -2630,6 +2628,8 @@ export class Toolbar extends FoundationElement { focusinHandler(e: FocusEvent): boolean | void; // @internal keydownHandler(e: KeyboardEvent): boolean | void; + // @internal + mouseDownHandler(e: MouseEvent): boolean | void; orientation: Orientation; // @internal protected reduceFocusableElements(): void; diff --git a/packages/web-components/fast-foundation/src/toolbar/toolbar.template.ts b/packages/web-components/fast-foundation/src/toolbar/toolbar.template.ts index 85fee48580c..417ab6e32e4 100644 --- a/packages/web-components/fast-foundation/src/toolbar/toolbar.template.ts +++ b/packages/web-components/fast-foundation/src/toolbar/toolbar.template.ts @@ -19,7 +19,7 @@ export const toolbarTemplate: FoundationElementTemplate< aria-orientation="${x => x.orientation}" orientation="${x => x.orientation}" role="toolbar" - @click="${(x, c) => x.clickHandler(c.event as MouseEvent)}" + @mousedown="${(x, c) => x.mouseDownHandler(c.event as MouseEvent)}" @focusin="${(x, c) => x.focusinHandler(c.event as FocusEvent)}" @keydown="${(x, c) => x.keydownHandler(c.event as KeyboardEvent)}" ${children({ diff --git a/packages/web-components/fast-foundation/src/toolbar/toolbar.ts b/packages/web-components/fast-foundation/src/toolbar/toolbar.ts index 967ce7ac78f..abb667b799f 100644 --- a/packages/web-components/fast-foundation/src/toolbar/toolbar.ts +++ b/packages/web-components/fast-foundation/src/toolbar/toolbar.ts @@ -131,8 +131,10 @@ export class Toolbar extends FoundationElement { * * @internal */ - public clickHandler(e: MouseEvent): boolean | void { - const activeIndex = this.focusableElements?.indexOf(e.target as HTMLElement); + public mouseDownHandler(e: MouseEvent): boolean | void { + const activeIndex = this.focusableElements?.findIndex(x => + x.contains(e.target as HTMLElement) + ); if (activeIndex > -1 && this.activeIndex !== activeIndex) { this.setFocusedElement(activeIndex); }