Skip to content
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,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "FocusZone: fixing logic to track outer FZ components correctly.",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "dzearing@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ export class FocusZone extends React.Component<IFocusZoneProps, {}> implements I
static defaultProps: IFocusZoneProps;
focus(forceIntoFirstElement?: boolean): boolean;
focusElement(element: HTMLElement): boolean;
static getOuterZones(): number;
// (undocumented)
render(): JSX.Element;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,28 @@ describe('FocusZone', () => {
expect(document.activeElement).toBe(host.querySelector('#b'));
});

it('only adds outerzones to be updated for tab changes', () => {
const activeZones = FocusZone.getOuterZones();

host = document.createElement('div');

// Render component without button A.
ReactDOM.render(
<FocusZone>
<FocusZone>
<button>ok</button>
</FocusZone>
</FocusZone>,
host
);

expect(FocusZone.getOuterZones()).toEqual(activeZones + 1);

ReactDOM.unmountComponentAtNode(host);

expect(FocusZone.getOuterZones()).toEqual(activeZones);
});

it('can call onActiveItemChanged when the active item is changed', () => {
let called = false;
const component = ReactTestUtils.renderIntoDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class FocusZone extends React.Component<IFocusZoneProps, {}> implements I
/** Used to allow us to move to next focusable element even when we're focusing on a input element when pressing tab */
private _processingTabKey: boolean;

/** Used for testing purposes only. */
public static getOuterZones(): number {
return _outerZones.size;
}

constructor(props: IFocusZoneProps) {
super(props);

Expand Down Expand Up @@ -108,10 +113,6 @@ export class FocusZone extends React.Component<IFocusZoneProps, {}> implements I

_allInstances[this._id] = this;

if (!this._isInnerZone) {
_outerZones.add(this);
}

if (root) {
const windowElement = root.ownerDocument!.defaultView;

Expand All @@ -125,6 +126,10 @@ export class FocusZone extends React.Component<IFocusZoneProps, {}> implements I
parentElement = getParent(parentElement, ALLOW_VIRTUAL_ELEMENTS);
}

if (!this._isInnerZone) {
_outerZones.add(this);
}

if (windowElement && _outerZones.size === 1) {
this._disposables.push(on(windowElement, 'keydown', this._onKeyDownCapture, true));
}
Expand Down