-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Update ExtendedPeoplePicker component to set the spellCheck and autoC… #7226
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
Closed
Closed
Changes from all commits
Commits
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/extended-people-picker-patch_2018-11-27-09-15.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": "Modify the ExtendedPeoplePicker so that the input props, spellcheck and autocorrect, are always set to false and off, respectively.", | ||
| "type": "minor" | ||
| } | ||
| ], | ||
| "packageName": "office-ui-fabric-react", | ||
| "email": "adameury@outlook.com" | ||
| } |
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
111 changes: 111 additions & 0 deletions
111
...-ui-fabric-react/src/components/ExtendedPicker/PeoplePicker/ExtendedPeoplePicker.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,111 @@ | ||
| /* tslint:disable:no-unused-variable */ | ||
| import * as React from 'react'; | ||
| /* tslint:enable:no-unused-variable */ | ||
| import * as renderer from 'react-test-renderer'; | ||
|
|
||
| import { Autofill } from '../../Autofill/index'; | ||
| import { IPersonaProps } from '../../Persona/index'; | ||
| import { people } from '../examples/PeopleExampleData'; | ||
| import { ExtendedPeoplePicker } from './ExtendedPeoplePicker'; | ||
| import { SuggestionsStore, FloatingPeoplePicker, IBaseFloatingPickerProps } from '../../FloatingPicker/index'; | ||
| import { ISelectedItemProps, IBaseSelectedItemsListProps, IExtendedPersonaProps, SelectedPeopleList } from '../../SelectedItemsList/index'; | ||
|
|
||
| function onResolveSuggestions(text: string): IPersonaProps[] { | ||
| const peopleList: IPersonaProps[] = people; | ||
| return peopleList.filter(p => p.text && p.text.includes(text)); | ||
| } | ||
|
|
||
| const floatingPickerProps = { | ||
| onResolveSuggestions: onResolveSuggestions, | ||
| suggestionsStore: new SuggestionsStore<IPersonaProps>() | ||
| }; | ||
|
|
||
| const basicItemRenderer = (props: ISelectedItemProps<IPersonaProps>) => { | ||
| return <div>{props.item.text}</div>; | ||
| }; | ||
|
|
||
| const selectedItemsListProps: IBaseSelectedItemsListProps<IPersonaProps> = { | ||
| onRenderItem: basicItemRenderer | ||
| }; | ||
|
|
||
| const onRenderFloatingPicker = (props: IBaseFloatingPickerProps<IPersonaProps>): JSX.Element => { | ||
| return <FloatingPeoplePicker {...props} />; | ||
| }; | ||
|
|
||
| const onRenderSelectedItems = (props: IBaseSelectedItemsListProps<IExtendedPersonaProps>): JSX.Element => { | ||
| return <SelectedPeopleList {...props} />; | ||
| }; | ||
|
|
||
| describe('Pickers', () => { | ||
| describe('ExtendedPeoplePicker', () => { | ||
| it('sets the Autofill spellCheck is set to false', () => { | ||
| const root = document.createElement('div'); | ||
| document.body.appendChild(root); | ||
|
|
||
| const pickerRenderer = renderer.create( | ||
| <ExtendedPeoplePicker | ||
| floatingPickerProps={floatingPickerProps} | ||
| selectedItemsListProps={selectedItemsListProps} | ||
| onRenderFloatingPicker={onRenderFloatingPicker} | ||
| onRenderSelectedItems={onRenderSelectedItems} | ||
| /> | ||
| ); | ||
| const pickerInstance = pickerRenderer.root; | ||
|
|
||
| expect(pickerInstance.findByType(Autofill).props.spellCheck).toBe(false); | ||
| }); | ||
|
|
||
| it('sets the Autofill autoCorrect prop to off', () => { | ||
| const root = document.createElement('div'); | ||
| document.body.appendChild(root); | ||
|
|
||
| const pickerRenderer = renderer.create( | ||
| <ExtendedPeoplePicker | ||
| floatingPickerProps={floatingPickerProps} | ||
| selectedItemsListProps={selectedItemsListProps} | ||
| onRenderFloatingPicker={onRenderFloatingPicker} | ||
| onRenderSelectedItems={onRenderSelectedItems} | ||
| /> | ||
| ); | ||
| const pickerInstance = pickerRenderer.root; | ||
|
|
||
| expect(pickerInstance.findByType(Autofill).props.autoCorrect).toBe('off'); | ||
| }); | ||
|
|
||
| it('overwrites spellCheck', () => { | ||
| const root = document.createElement('div'); | ||
| document.body.appendChild(root); | ||
|
|
||
| const pickerRenderer = renderer.create( | ||
| <ExtendedPeoplePicker | ||
| floatingPickerProps={floatingPickerProps} | ||
| selectedItemsListProps={selectedItemsListProps} | ||
| onRenderFloatingPicker={onRenderFloatingPicker} | ||
| onRenderSelectedItems={onRenderSelectedItems} | ||
| inputProps={{ spellCheck: true }} | ||
| /> | ||
| ); | ||
| const pickerInstance = pickerRenderer.root; | ||
|
|
||
| expect(pickerInstance.findByType(Autofill).props.spellCheck).toBe(false); | ||
| }); | ||
|
|
||
| it('overwrites autoCorrect', () => { | ||
| const root = document.createElement('div'); | ||
| document.body.appendChild(root); | ||
|
|
||
| const pickerRenderer = renderer.create( | ||
| <ExtendedPeoplePicker | ||
| floatingPickerProps={floatingPickerProps} | ||
| selectedItemsListProps={selectedItemsListProps} | ||
| onRenderFloatingPicker={onRenderFloatingPicker} | ||
| onRenderSelectedItems={onRenderSelectedItems} | ||
| inputProps={{ autoCorrect: 'on' }} | ||
| /> | ||
| ); | ||
| const pickerInstance = pickerRenderer.root; | ||
|
|
||
| expect(pickerInstance.findByType(Autofill).props.autoCorrect).toBe('off'); | ||
| }); | ||
| }); | ||
| }); |
13 changes: 11 additions & 2 deletions
13
...ffice-ui-fabric-react/src/components/ExtendedPicker/PeoplePicker/ExtendedPeoplePicker.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 |
|---|---|---|
| @@ -1,17 +1,26 @@ | ||
| /* tslint:disable */ | ||
| import { IPickerItemProps } from '../../../Pickers'; | ||
| import { IPickerItemProps, IInputProps } from '../../../Pickers'; | ||
| /* tslint:enable */ | ||
|
|
||
| import { IExtendedPersonaProps } from '../../../SelectedItemsList'; | ||
| import { IPersonaProps } from '../../../Persona'; | ||
| import './ExtendedPeoplePicker.scss'; | ||
| import { BaseExtendedPicker } from '../BaseExtendedPicker'; | ||
| import { IBaseExtendedPickerProps } from '../BaseExtendedPicker.types'; | ||
| import { assign } from '@uifabric/utilities'; | ||
|
|
||
| export interface IPeoplePickerItemProps extends IPickerItemProps<IExtendedPersonaProps> {} | ||
|
|
||
| export interface IExtendedPeoplePickerProps extends IBaseExtendedPickerProps<IPersonaProps> {} | ||
|
|
||
| export class BaseExtendedPeoplePicker extends BaseExtendedPicker<IPersonaProps, IExtendedPeoplePickerProps> {} | ||
|
|
||
| export class ExtendedPeoplePicker extends BaseExtendedPeoplePicker {} | ||
| export class ExtendedPeoplePicker extends BaseExtendedPeoplePicker { | ||
| protected inputProps = (): IInputProps => { | ||
| const overwrittenInputProps: IInputProps = { | ||
| autoCorrect: 'off', | ||
| spellCheck: false | ||
| }; | ||
| return assign({}, this.props.inputProps, overwrittenInputProps); | ||
| }; | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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 don't think that this is the right way to achieve this. Instead you could do something like
That way you don't need to mess with your BaseExtendedPicker, you don't need to have a method called, and you can use the component ref stuff to ensure you won't lose out on the interface methods you might call.
For example of how some of this works, check out the various buttons. Although I'm not 100% we want to continue that pattern. @dzearing or @micahgodbolt what are your thoughts?
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.
@JasonGore may have some thoughts on how to best override component props from the base class here when he has a moment.
Uh oh!
There was an error while loading. Please reload this page.
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.
The best way (and official React way) is not to use inheritance at all.
In this case, I think the sanest approach is just to do:
If there is a reason not to use composition, then at the very least @joschect's advice should be taken as it doesn't require the base class to be modified at all and
inputPropsmember can be removed.[EDIT] Code corrected per my latest comments below.
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.
(Changed to
extends BaseComponentto make sure refs still work.)Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for the input @joschect and @JasonGore! My initial thought was to go with something similar to what @joschect suggested, but I thought it was a bit weird to render the component that it's also extending. I was aware of the official recommendation of not using component inheritance, but I didn't want to make that assumption for this project and remove it without further input.
I like @JasonGore's suggestion, but am happy to go with @joschect if desired.
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.
Oops, I was wrong about my comment. Extending
React.Componentshould be sufficient. Similar to our other HOC wrappers (styled, etc.) the refs will just get forwarded in the props and should continue to work fine.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.
@aleury Go with Jason's suggestion, it looks more correct.