Skip to content
Merged
Changes from 1 commit
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
Expand Up @@ -221,6 +221,7 @@ export class FocusZone extends BaseComponent<IFocusZoneProps, {}> implements IFo
while (parentElement && parentElement !== this._root.value) {
if (isElementTabbable(parentElement) && this._isImmediateDescendantOfZone(parentElement)) {
this._activeElement = parentElement;
this._setFocusAlignment(this._activeElement);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will cause focus to be "pulled" to one side for variable sized boxes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. The code at lines 216-217 run when the event target is the immediate descendent of the parent. If it's not, this while loop just finds the parent element that is an immediate descendent, and should therefore be running the same code once it finds that parent element. Looks like a bug that we were only updating focus alignment if the focused element was a top level element.

The case where focus gets pulled to the side was caused by my changes down in _setFocusAlignment(), e.g. we only want to update the horizontal alignment when going left or right, the onFocus shouldn't update the alignment except for the case where no alignment was previously set.

break;
}
parentElement = getParent(parentElement, ALLOW_VIRTUAL_ELEMENTS) as HTMLElement;
Expand Down Expand Up @@ -696,24 +697,13 @@ export class FocusZone extends BaseComponent<IFocusZoneProps, {}> implements IFo
}

private _setFocusAlignment(element: HTMLElement, isHorizontal?: boolean, isVertical?: boolean) {
if (this.props.direction === FocusZoneDirection.bidirectional &&
(!this._focusAlignment || isHorizontal || isVertical)) {
if (this.props.direction === FocusZoneDirection.bidirectional) {

const rect = element.getBoundingClientRect();
const left = rect.left + (rect.width / 2);
const top = rect.top + (rect.height / 2);

if (!this._focusAlignment) {
this._focusAlignment = { left, top };
}

if (isHorizontal) {
this._focusAlignment.left = left;
}

if (isVertical) {
this._focusAlignment.top = top;
}
this._focusAlignment = { left, top };
}
}

Expand Down