Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
de2ca14
undo.
dzearing Mar 14, 2018
e77281d
initial scaffolding
dzearing Jan 17, 2019
c5515f8
formatting
dzearing Jan 17, 2019
a6069ed
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
dzearing Jan 17, 2019
aa2c6b1
updates
dzearing Jan 22, 2019
4cdb158
Tests are working.
dzearing Jan 24, 2019
a0404aa
Merge branch 'focuszone' of https://github.com/dzearing/office-ui-fab…
dzearing Jan 25, 2019
f9ee9dd
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
dzearing Jan 28, 2019
6edeaf2
changes.
dzearing Jan 28, 2019
66ab5e3
Changes
dzearing Jan 28, 2019
c47a3a1
undo ftz test issue.
dzearing Jan 28, 2019
a545c20
Updates to tests.
dzearing Jan 28, 2019
f11300a
api
dzearing Jan 28, 2019
a8e8b9c
Only restore focus on unpark when needed.
dzearing Jan 29, 2019
80c400e
Updates
dzearing Jan 30, 2019
8bedfd4
adjustments
dzearing Jan 30, 2019
d38574a
Updates to the photos example (you can click to remove a photo) and f…
dzearing Jan 30, 2019
e1ed53a
Fixign build.
dzearing Jan 30, 2019
70b24fb
More updates
dzearing Jan 30, 2019
b98cba9
updating snapshots.
dzearing Jan 30, 2019
7b9e54b
Moving utils to utils.
dzearing Jan 31, 2019
1e67449
updates to api.
dzearing Jan 31, 2019
be3f29b
Adding tests.
dzearing Jan 31, 2019
8832984
undo merge issues.
dzearing Jan 31, 2019
33e187d
woot
dzearing Jan 31, 2019
f85f09e
Snapshot updates.
dzearing Jan 31, 2019
65db0c3
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
dzearing Jan 31, 2019
4b12dc4
fix
dzearing Jan 31, 2019
c44e894
Adding comments on park helper.
dzearing Jan 31, 2019
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": [
{
"comment": "Adding helper functions to get and restore focus elements based on index paths.",
"packageName": "@uifabric/utilities",
"type": "minor"
}
],
"packageName": "@uifabric/utilities",
"email": "dzearing@microsoft.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "FocusZone: focus can now be recovered if focus was resting within the zone but the element was removed.",
"type": "minor"
}
],
"packageName": "office-ui-fabric-react",
"email": "dzearing@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,8 @@ class FocusZone extends BaseComponent<IFocusZoneProps, {}>, implements IFocusZon
// (undocumented)
componentDidMount(): void;
// (undocumented)
componentDidUpdate(): void;
// (undocumented)
componentWillUnmount(): void;
// (undocumented)
static defaultProps: IFocusZoneProps;
Expand Down Expand Up @@ -1352,6 +1354,9 @@ export function getDistanceBetweenPoints(point1: IPoint, point2: IPoint): number
// @public
export function getDocument(rootElement?: HTMLElement | null): Document | undefined;

// @public
export function getElementIndexPath(fromElement: HTMLElement, toElement: HTMLElement): number[];

// @public
export function getFadedOverflowStyle(theme: ITheme, color?: keyof ISemanticColors | keyof IPalette, direction?: 'horizontal' | 'vertical', width?: string | number, height?: string | number): IRawStyle;

Expand All @@ -1361,6 +1366,9 @@ export function getFirstFocusable(rootElement: HTMLElement, currentElement: HTML
// @public
export function getFirstTabbable(rootElement: HTMLElement, currentElement: HTMLElement, includeElementsInFocusZones?: boolean): HTMLElement | null;

// @public
export function getFocusableByIndexPath(parent: HTMLElement, path: number[]): HTMLElement | undefined;

// @public
export function getFocusStyle(theme: ITheme, inset?: number, position?: 'relative' | 'absolute', highContrastStyle?: IRawStyle | undefined, borderColor?: string, outlineColor?: string, isFocusedOnly?: boolean): IRawStyle;

Expand Down
3 changes: 2 additions & 1 deletion packages/office-ui-fabric-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@uifabric/jest-serializer-merge-styles": ">=6.0.7 <7.0.0",
"@uifabric/prettier-rules": ">=1.0.0 <2.0.0",
"@uifabric/tslint-rules": ">=1.0.0 <2.0.0",
"@uifabric/test-utilities": ">=6.0.0 <7.0.0",
"@uifabric/webpack-utils": ">=0.7.4 <1.0.0",
"enzyme": "^3.4.1",
"enzyme-adapter-react-16": "^1.2.0",
Expand Down Expand Up @@ -76,4 +77,4 @@
"react": ">=16.3.2-0 <17.0.0",
"react-dom": ">=16.3.2-0 <17.0.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('FocusTrapZone', () => {
beforeEach(() => {
lastFocusedElement = undefined;
});

describe('Tab and shift-tab wrap at extreme ends of the FTZ', () => {
it('can tab across FocusZones with different button structures', async () => {
expect.assertions(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import * as React from 'react';

import * as ReactDOM from 'react-dom';
import * as ReactTestUtils from 'react-dom/test-utils';
import { setRTL, KeyCodes } from '../../Utilities';

import { FocusZone } from './FocusZone';
import { FocusZoneDirection, FocusZoneTabbableElements } from './FocusZone.types';

// tslint:disable:typedef

describe('FocusZone', () => {
let lastFocusedElement: HTMLElement | undefined;
let host: HTMLElement;

afterEach(() => {
if (host) {
ReactDOM.unmountComponentAtNode(host);
(host as any) = undefined;
}
});

function _onFocus(ev: any): void {
lastFocusedElement = ev.target;
}
Expand Down Expand Up @@ -143,6 +152,159 @@ describe('FocusZone', () => {
expect(lastFocusedElement).toBe(buttonC);
});

it('can restore focus to the following item when item removed', () => {
host = document.createElement('div');

// Render component.
ReactDOM.render(
<FocusZone>
<button key="a" id="a" data-is-visible="true">
button a
</button>
<button key="b" id="b" data-is-visible="true">
button b
</button>
<button key="c" id="c" data-is-visible="true">
button c
</button>
</FocusZone>,
host
);

const buttonB = host.querySelector('#b') as HTMLElement;

buttonB.focus();

// Render component without button A.
ReactDOM.render(
<FocusZone>
<button key="a" id="a" data-is-visible="true">
button a
</button>
<button key="c" id="c" data-is-visible="true">
button c
</button>
</FocusZone>,
host
);

expect(document.activeElement).toBe(host.querySelector('#c'));
});

it('can restore focus to the previous item when end item removed', () => {
host = document.createElement('div');

// Render component.
ReactDOM.render(
<FocusZone>
<button key="a" id="a" data-is-visible="true">
button a
</button>
<button key="b" id="b" data-is-visible="true">
button b
</button>
<button key="c" id="c" data-is-visible="true">
button c
</button>
</FocusZone>,
host
);

const buttonC = host.querySelector('#c') as HTMLElement;

buttonC.focus();

// Render component without button A.
ReactDOM.render(
<FocusZone>
<button key="a" id="a" data-is-visible="true">
button a
</button>
<button key="b" id="b" data-is-visible="true">
button b
</button>
</FocusZone>,
host
);

expect(document.activeElement).toBe(host.querySelector('#b'));
});

describe('parking and unparking', () => {
let buttonA: HTMLElement;

beforeEach(() => {
host = document.createElement('div');

// Render component.
ReactDOM.render(
<div>
<button key="z" id="z" data-is-visible="true" />
<FocusZone id="fz">
<button key="a" id="a" data-is-visible="true">
button a
</button>
</FocusZone>
</div>,
host
);
buttonA = host.querySelector('#a') as HTMLElement;
buttonA.focus();

// Render component without button A.
ReactDOM.render(
<div>
<button key="z" id="z" data-is-visible="true" />
<FocusZone id="fz" />
</div>,
host
);
});

it('can move focus to container when last item removed', () => {
expect(document.activeElement).toBe(host.querySelector('#fz'));
});

it('can move focus from container to first item when added', () => {
ReactDOM.render(
<div>
<button key="z" id="z" />
<FocusZone id="fz">
<button key="a" id="a" data-is-visible="true">
button a
</button>
</FocusZone>
</div>,
host
);
expect(document.activeElement).toBe(host.querySelector('#a'));
});

it('removes focusability when moving from focused container', () => {
expect(host.querySelector('#fz')!.getAttribute('tabindex')).toEqual('-1');
(host.querySelector('#z') as HTMLElement).focus();
expect(host.querySelector('#fz')!.getAttribute('tabindex')).toBeNull();
});

it('does not move focus when items added without container focus', () => {
expect(host.querySelector('#fz')!.getAttribute('tabindex')).toEqual('-1');
(host.querySelector('#z') as HTMLElement).focus();

ReactDOM.render(
<div>
<button key="z" id="z" />
<FocusZone id="fz">
<button key="a" id="a" data-is-visible="true">
button a
</button>
</FocusZone>
</div>,
host
);
expect(document.activeElement).toBe(host.querySelector('#z'));
});
});

it('can ignore arrowing if default is prevented', () => {
const component = ReactTestUtils.renderIntoDocument(
<div {...{ onFocusCapture: _onFocus }}>
Expand Down
Loading