-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[Do not review] Enabling selection for input changed for UnifiedPicker and updating example for that case #15412
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6bcd9ac
adding input change in double upp example
nebhatna 3269d29
hacky way to clear input text
nebhatna 27cb5cd
meh
nebhatna 1889b91
fixed example and hacky way of clearing input
nebhatna ae4e034
fixing the bug
nebhatna f58590f
add example
nebhatna 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
This file contains 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 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 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 |
---|---|---|
|
@@ -58,6 +58,8 @@ const UnifiedPeoplePickerExample = (): JSX.Element => { | |
..._suggestions, | ||
]); | ||
|
||
const ref = React.useRef<any>(); | ||
|
||
const [peopleSelectedItems, setPeopleSelectedItems] = React.useState<IPersonaProps[]>([]); | ||
|
||
const _onSuggestionSelected = ( | ||
|
@@ -102,26 +104,6 @@ const UnifiedPeoplePickerExample = (): JSX.Element => { | |
return copyText; | ||
}; | ||
|
||
const _onPaste = (pastedValue: string, selectedItemsList: IPersonaProps[]): void => { | ||
// Find the suggestion corresponding to the specific text name | ||
// and update the selectedItemsList to re-render everything. | ||
const newList: IPersonaProps[] = []; | ||
if (pastedValue !== null) { | ||
pastedValue.split(',').forEach(textValue => { | ||
if (textValue) { | ||
people.forEach(suggestionItem => { | ||
if (suggestionItem.text === textValue) { | ||
selectedItemsList.push(suggestionItem); | ||
newList.push(suggestionItem); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
setPeopleSelectedItems(prevPeopleSelectedItems => [...prevPeopleSelectedItems, ...newList]); | ||
}; | ||
|
||
const _serializeItemsForDrag = (items: IPersonaProps[]): string => { | ||
return _getItemsCopyText(items); | ||
}; | ||
|
@@ -179,14 +161,54 @@ const UnifiedPeoplePickerExample = (): JSX.Element => { | |
setPeopleSelectedItems(updatedItems); | ||
}; | ||
|
||
const _onInputChange = (filterText: string): void => { | ||
const SEPARATOR_REGEX = new RegExp(';|,|\\n|\u000A', 'g'); | ||
const splitPasteInputIntoRecipientStrings = (inputText: string) => | ||
inputText | ||
.split(SEPARATOR_REGEX) | ||
.map((token: string) => token.trim()) | ||
.filter((token: string) => !!token); | ||
|
||
const _onInputChange = (filterText: string, composing?: boolean, resultItemsList?: IPersonaProps[]): void => { | ||
const allPeople = people; | ||
|
||
const lastCharIndex = filterText.length - 1; | ||
const lastChar = filterText[lastCharIndex]; | ||
const suggestions = allPeople.filter((item: IPersonaProps) => _startsWith(item.text || '', filterText)); | ||
const suggestionList = suggestions.map(item => { | ||
return { item: item, isSelected: false, key: item.key } as IFloatingSuggestionItem<IPersonaProps>; | ||
}); | ||
// We want to show top 5 results | ||
setPeopleSuggestions(suggestionList.splice(0, 5)); | ||
|
||
const updatedItems: IPersonaProps[] = []; | ||
const currentItems: IPersonaProps[] = [...peopleSelectedItems]; | ||
|
||
for (let i = 0; i < currentItems.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need this, you can have the declaration be this right? |
||
const item = currentItems[i]; | ||
updatedItems.push(item); | ||
} | ||
|
||
if (lastChar == ';' || lastChar == ',') { | ||
const pastedText = splitPasteInputIntoRecipientStrings(filterText); | ||
pastedText.forEach(function(itemText) { | ||
let result; | ||
const extractedText = itemText.substring(0, lastCharIndex); | ||
// We need to do an exact match | ||
|
||
allPeople.forEach((item: IPersonaProps) => { | ||
if (item.text.toLowerCase() == extractedText.toLowerCase()) { | ||
result = item; | ||
} | ||
}); | ||
|
||
if (result && resultItemsList) { | ||
resultItemsList.push(result); | ||
updatedItems.push(result); | ||
} | ||
setPeopleSelectedItems(updatedItems); | ||
}); | ||
} else { | ||
// We want to show top 5 results | ||
setPeopleSuggestions(suggestionList.splice(0, 5)); | ||
} | ||
}; | ||
|
||
function _startsWith(text: string, filterText: string): boolean { | ||
|
@@ -222,13 +244,12 @@ const UnifiedPeoplePickerExample = (): JSX.Element => { | |
return ( | ||
<> | ||
<UnifiedPeoplePicker | ||
componentRef={ref} | ||
selectedItemsListProps={selectedPeopleListProps} | ||
floatingSuggestionProps={floatingPeoplePickerProps} | ||
inputProps={inputProps} | ||
// eslint-disable-next-line react/jsx-no-bind | ||
onInputChange={_onInputChange} | ||
// eslint-disable-next-line react/jsx-no-bind | ||
onPaste={_onPaste} | ||
customClipboardType="recipients" | ||
/> | ||
</> | ||
|
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.
Would this (resultItemList) ever have a value?
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.
yes, it would, this is what is getting updated