forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(react-tag-picker): support TagPicker usage without TagPickerL…
…ist (microsoft#32158)
- Loading branch information
1 parent
8cdc1ca
commit cb6df91
Showing
11 changed files
with
148 additions
and
33 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-tag-picker-f6c70a8c-6231-41fe-baa5-ce7d1e65417a.json
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "feature: introduces noPopover property to TagPicker", | ||
"packageName": "@fluentui/react-tag-picker", | ||
"email": "bernardo.sunderhus@gmail.com", | ||
"dependentChangeType": "patch" | ||
} |
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
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
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
64 changes: 64 additions & 0 deletions
64
...es/react-components/react-tag-picker/stories/src/TagPicker/TagPickerNoPopover.stories.tsx
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as React from 'react'; | ||
import { | ||
TagPicker, | ||
TagPickerInput, | ||
TagPickerControl, | ||
TagPickerProps, | ||
TagPickerGroup, | ||
} from '@fluentui/react-components'; | ||
import { Tag, Avatar, Field } from '@fluentui/react-components'; | ||
|
||
export const NoPopover = () => { | ||
const [selectedOptions, setSelectedOptions] = React.useState<string[]>([]); | ||
const [inputValue, setInputValue] = React.useState(''); | ||
|
||
const onOptionSelect: TagPickerProps['onOptionSelect'] = (_, data) => { | ||
setSelectedOptions(data.selectedOptions); | ||
}; | ||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setInputValue(event.currentTarget.value); | ||
}; | ||
const handleKeyDown = (event: React.KeyboardEvent) => { | ||
if (event.key === 'Enter' && inputValue) { | ||
setInputValue(''); | ||
setSelectedOptions(curr => (curr.includes(inputValue) ? curr : [...curr, inputValue])); | ||
} | ||
}; | ||
|
||
return ( | ||
<Field label="Add Employees" style={{ maxWidth: 400 }}> | ||
<TagPicker noPopover onOptionSelect={onOptionSelect} selectedOptions={selectedOptions}> | ||
<TagPickerControl> | ||
<TagPickerGroup> | ||
{selectedOptions.map((option, index) => ( | ||
<Tag | ||
key={index} | ||
shape="rounded" | ||
media={<Avatar aria-hidden name={option} color="colorful" />} | ||
value={option} | ||
> | ||
{option} | ||
</Tag> | ||
))} | ||
</TagPickerGroup> | ||
<TagPickerInput | ||
value={inputValue} | ||
onChange={handleChange} | ||
onKeyDown={handleKeyDown} | ||
aria-label="Add Employees" | ||
/> | ||
</TagPickerControl> | ||
</TagPicker> | ||
</Field> | ||
); | ||
}; | ||
|
||
NoPopover.parameters = { | ||
docs: { | ||
description: { | ||
story: ` | ||
You can use the \`TagPicker\` without the popover with the list of options by providing the \`noPopover\` property. This is useful when you want to allow users to input their own tags. All you have to do is control the \`TagPickerInput\` value and handle the \`onKeyDown\` event to add the tag to the \`TagPicker\` when the user presses the Enter key. | ||
`, | ||
}, | ||
}, | ||
}; |
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