-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: introduces noPopover property to TagPicker
- Loading branch information
1 parent
c5f2c9f
commit 979c4da
Showing
6 changed files
with
91 additions
and
6 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
65 changes: 65 additions & 0 deletions
65
...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,65 @@ | ||
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 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, inputValue]); | ||
} | ||
}; | ||
|
||
const [inputValue, setInputValue] = React.useState(''); | ||
|
||
return ( | ||
<Field label="Add Employees" style={{ maxWidth: 400 }}> | ||
<TagPicker noPopover onOptionSelect={onOptionSelect} selectedOptions={selectedOptions}> | ||
<TagPickerControl expandIcon={null}> | ||
<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