Skip to content

Commit

Permalink
add tag for newly added options when create option is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
bmartel committed Aug 8, 2021
1 parent 140ee16 commit dc1bfc6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ const _options = items.map((label) => ({ label, value: label.toLowerCase() }))
const StatefulMultiSelect: FC<
Omit<MultiSelectProps, 'onChange' | 'value'> &
Partial<Pick<MultiSelectProps, 'onChange' | 'value'>>
> = ({ onChange: _onChange, value: _value, ...props }) => {
> = ({ onChange: _onChange, value: _value, options: __options, ...props }) => {
const { value, options, onChange } = useMultiSelect({
value: _value || props.single ? '' : [],
options: props.options!,
options: __options!,
onChange: _onChange,
})

Expand Down
14 changes: 12 additions & 2 deletions src/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const SelectLabel = memo<HTMLChakraProps<'label'>>((props) => {
SelectLabel.displayName = 'SelectLabel'

export const SelectOptionItem = memo<SelectOptionItemProps>(
({ value, label, index, selected, ...props }) => {
({ value, label, index, selected, created, ...props }) => {
const { highlightedRef, option, ...itemProps } = useSelectItem({
value,
label,
Expand All @@ -123,7 +123,16 @@ export const SelectOptionItem = memo<SelectOptionItemProps>(
{...props}
{...itemProps}
>
{option?.label || value}
<HStack justifyContent='space-between' w='full'>
<Box>{option?.label || value}</Box>
{!!created && (
<Tag flexShrink={0}>
<TagLabel fontSize='xs' fontWeight='bold'>
New
</TagLabel>
</Tag>
)}
</HStack>
</chakra.li>
)
}
Expand All @@ -148,6 +157,7 @@ export const SelectList = memo(() => {
value: optionItem.value,
label: optionItem.label || labelFromValue(optionItem.value),
selected: optionItem.selected,
created: optionItem.created,
index,
}
},
Expand Down

0 comments on commit dc1bfc6

Please sign in to comment.