Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick] Fix two toolbar focus issues #6851

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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