-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[DetailsList] Add public focusIndex function #3852
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
Merged
lambertwang-zz
merged 7 commits into
microsoft:master
from
lambertwang-zz:magellan/detailsListRowFocus
Feb 23, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
59caaef
[Focus] Enable focus forceIntoFirstElement parameter
lambertwang-zz edf211d
Change file
lambertwang-zz 0445940
Fixed formatting
lambertwang-zz e68bf20
Merge branch 'master' of github.com:lambertwang/office-ui-fabric-reac…
lambertwang-zz db3c4c1
Added DetailsList test and public api
lambertwang-zz c647195
Merge branch 'master' of github.com:OfficeDev/office-ui-fabric-react …
lambertwang-zz 74255a8
Fixed build errors
lambertwang-zz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/office-ui-fabric-react/magellan-detailsListRowFocus_2018-01-31-23-40.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "office-ui-fabric-react", | ||
| "comment": "[Focus] Enable focus forceIntoFirstElement parameter", | ||
| "type": "patch" | ||
| } | ||
| ], | ||
| "packageName": "office-ui-fabric-react", | ||
| "email": "law@microsoft.com" | ||
| } |
114 changes: 114 additions & 0 deletions
114
packages/office-ui-fabric-react/src/components/DetailsList/DetailsList.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import * as React from 'react'; | ||
| import * as renderer from 'react-test-renderer'; | ||
| import * as ReactTestUtils from 'react-dom/test-utils'; | ||
| import { mount } from 'enzyme'; | ||
|
|
||
| import { | ||
| DetailsList | ||
| } from './DetailsList'; | ||
|
|
||
| import { | ||
| IDetailsList, | ||
| IColumn | ||
| } from './DetailsList.types'; | ||
|
|
||
| // Populate mock items for testing | ||
| function mockItems(count: number): any { | ||
| const items = []; | ||
|
|
||
| for (let i = 0; i < count; i++) { | ||
| items.push({ | ||
| key: i, | ||
| name: 'Item ' + i, | ||
| value: i | ||
| }); | ||
| } | ||
|
|
||
| return items; | ||
| } | ||
|
|
||
| describe('DetailsList', () => { | ||
| it('renders List correctly', () => { | ||
| DetailsList.prototype.componentDidMount = jest.fn(); | ||
|
|
||
| const component = renderer.create( | ||
| <DetailsList | ||
| items={ mockItems(5) } | ||
| // tslint:disable-next-line:jsx-no-lambda | ||
| onRenderRow={ () => null } | ||
| skipViewportMeasures={ true } | ||
| // tslint:disable-next-line:jsx-no-lambda | ||
| onShouldVirtualize={ () => false } | ||
| /> | ||
| ); | ||
| const tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('focuses row by index', () => { | ||
| jest.useFakeTimers(); | ||
|
|
||
| let component: any; | ||
| const wrapper = mount( | ||
| <DetailsList | ||
| items={ mockItems(5) } | ||
| // tslint:disable-next-line:jsx-no-lambda | ||
| componentRef={ ref => component = ref } | ||
| skipViewportMeasures={ true } | ||
| // tslint:disable-next-line:jsx-no-lambda | ||
| onShouldVirtualize={ () => false } | ||
| />); | ||
|
|
||
| expect(component).toBeDefined(); | ||
| (component as IDetailsList).focusIndex(2); | ||
| setTimeout(() => { | ||
| expect(document.activeElement.className.split(' ')).toContain('ms-DetailsRow'); | ||
| expect(document.activeElement.textContent).toEqual('2'); | ||
| }, 0); | ||
| jest.runOnlyPendingTimers(); | ||
| }); | ||
|
|
||
| it('focuses into row element', () => { | ||
| const onRenderColumn = (item: any, index: number, column: IColumn) => { | ||
| let value = (item && column && column.fieldName) ? item[column.fieldName] : ''; | ||
| if (value === null || value === undefined) { | ||
| value = ''; | ||
| } | ||
| console.log('Rendered column'); | ||
| return ( | ||
| <div className={ 'test-column' } data-is-focusable={ true } > | ||
| { value } | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| jest.useFakeTimers(); | ||
|
|
||
| let component: any; | ||
| const wrapper = mount( | ||
| <DetailsList | ||
| items={ mockItems(5) } | ||
| // tslint:disable-next-line:jsx-no-lambda | ||
| componentRef={ ref => component = ref } | ||
| skipViewportMeasures={ true } | ||
| // tslint:disable-next-line:jsx-no-lambda | ||
| onShouldVirtualize={ () => false } | ||
| onRenderItemColumn={ onRenderColumn } | ||
| />); | ||
|
|
||
| expect(component).toBeDefined(); | ||
| (component as IDetailsList).focusIndex(2); | ||
| setTimeout(() => { | ||
| expect(document.activeElement.className.split(' ')).toContain('ms-DetailsRow'); | ||
| expect(document.activeElement.textContent).toEqual('2'); | ||
| }, 0); | ||
| jest.runOnlyPendingTimers(); | ||
|
|
||
| (component as IDetailsList).focusIndex(2, true); | ||
| setTimeout(() => { | ||
| expect(document.activeElement.className.split(' ')).toContain('test-column'); | ||
| expect(document.activeElement.textContent).toEqual('2'); | ||
| }, 0); | ||
| jest.runOnlyPendingTimers(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,5 +91,4 @@ export class DetailsRowFields extends BaseComponent<IDetailsRowFieldsProps, IDet | |
|
|
||
| return value; | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a public API being added, but no change to a .types file.
It would also be great to use enzyme and write some tests to cover these things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.