Skip to content

Commit

Permalink
[cherry-pick] Fix two toolbar focus issues (#6851)
Browse files Browse the repository at this point in the history
* Fix bug in toolbar click handler when a slotted element has child elements (#6830)

* Fix bug with nested elements in toolbar click handler

* Change files

* lint

* update change description

* slight test improvement

* Update change/@microsoft-fast-foundation-2ada25c3-3fb4-48ba-893d-e64d11f7f095.json

---------

Co-authored-by: Chris Holt <[email protected]>

* Fix toolbar focus bug (#6836)

* Fix focus issue when clicking on an element in the toolbar

* remove describe.only

* Change files

* Update api-report.md

* Update change/@microsoft-fast-foundation-903a969b-3de3-4090-974a-3423344c571c.json

---------

Co-authored-by: Chris Holt <[email protected]>

* update change files

* revert unintended change

---------

Co-authored-by: Chris Holt <[email protected]>
  • Loading branch information
mollykreis and chrisdholt authored Oct 25, 2023
1 parent 21f8185 commit 507d2fe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix focus issues with toolbar",
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions packages/web-components/fast-foundation/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 507d2fe

Please sign in to comment.