Skip to content

Commit 5f5e887

Browse files
dzearingKevinTCoughlin
authored andcommitted
Focuszone: onActiveItemChanged now fires (#7958)
* Reverting focuszone activeelementchanged change, and adding a test. * Adding change file. * Remove lint issue
1 parent cbfcd33 commit 5f5e887

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "office-ui-fabric-react",
5+
"comment": "FocusZone: fixing issue where onActiveItemChanged was no longer firing.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "office-ui-fabric-react",
10+
"email": "dzearing@microsoft.com"
11+
}

packages/office-ui-fabric-react/src/components/FocusZone/FocusZone.test.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { setRTL, KeyCodes } from '../../Utilities';
55
import { FocusZone } from './FocusZone';
66
import { FocusZoneDirection, FocusZoneTabbableElements } from './FocusZone.types';
77

8-
// tslint:disable:typedef
8+
// tslint:disable:typedef jsx-no-lambda
99

1010
describe('FocusZone', () => {
1111
let lastFocusedElement: HTMLElement | undefined;
@@ -230,6 +230,35 @@ describe('FocusZone', () => {
230230
expect(document.activeElement).toBe(host.querySelector('#b'));
231231
});
232232

233+
it('can call onActiveItemChanged when the active item is changed', () => {
234+
let called = false;
235+
const component = ReactTestUtils.renderIntoDocument(
236+
<FocusZone onActiveElementChanged={() => (called = true)}>
237+
<button key="a" id="a" data-is-visible="true">
238+
button a
239+
</button>
240+
<button key="b" id="b" data-is-visible="true">
241+
button b
242+
</button>
243+
</FocusZone>
244+
);
245+
const focusZone = ReactDOM.findDOMNode(component as React.ReactInstance)!!.firstChild as Element;
246+
const buttonA = focusZone.querySelector('#a') as HTMLElement;
247+
const buttonB = focusZone.querySelector('#b') as HTMLElement;
248+
249+
ReactTestUtils.Simulate.mouseDown(focusZone, { target: buttonA });
250+
ReactTestUtils.Simulate.focus(focusZone, { target: buttonA });
251+
252+
expect(called).toEqual(true);
253+
called = false;
254+
255+
ReactTestUtils.Simulate.mouseDown(focusZone, { target: buttonB });
256+
ReactTestUtils.Simulate.focus(focusZone, { target: buttonB });
257+
258+
expect(called).toEqual(true);
259+
called = false;
260+
});
261+
233262
describe('parking and unparking', () => {
234263
let buttonA: HTMLElement;
235264

packages/office-ui-fabric-react/src/components/FocusZone/FocusZone.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ export class FocusZone extends BaseComponent<IFocusZoneProps, {}> implements IFo
293293
if (isImmediateDescendant) {
294294
this._setFocusAlignment(this._activeElement);
295295
}
296+
}
296297

297-
if (onActiveElementChanged) {
298-
onActiveElementChanged(this._activeElement as HTMLElement, ev);
299-
}
298+
if (onActiveElementChanged) {
299+
onActiveElementChanged(this._activeElement as HTMLElement, ev);
300300
}
301301

302302
if (doNotAllowFocusEventToPropagate) {

0 commit comments

Comments
 (0)