Skip to content

Commit

Permalink
feat: make select option show description
Browse files Browse the repository at this point in the history
  • Loading branch information
skinmaker1345 committed Jul 20, 2024
1 parent 1c94196 commit 6866864
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion components/Form/Selects.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { MouseEventHandler } from 'react'
import ReactSelect, { components, MultiValueProps, MultiValueRemoveProps } from 'react-select'
import ReactSelect, {
components,
MultiValueProps,
MultiValueRemoveProps,
OptionProps,
} from 'react-select'
import { closestCenter, DndContext, DragEndEvent } from '@dnd-kit/core'
import { restrictToParentElement } from '@dnd-kit/modifiers'
import {
Expand Down Expand Up @@ -43,6 +48,17 @@ const MultiValueRemove = (props: MultiValueRemoveProps<Option>) => {
)
}

const Option = ({ ...props }: OptionProps<Option>) => {
return (
<components.Option {...props}>
<div className='flex flex-col'>
<span>{props.data.label}</span>
<span className='text-sm font-light opacity-90'>{props.data.description}</span>
</div>
</components.Option>
)
}

const Select: React.FC<SelectProps> = ({
placeholder,
options,
Expand Down Expand Up @@ -97,6 +113,7 @@ const Select: React.FC<SelectProps> = ({
components={{
MultiValue,
MultiValueRemove,
Option,
}}
closeMenuOnSelect={false}
/>
Expand All @@ -117,6 +134,7 @@ interface SelectProps {
interface Option {
value: string
label: string
description?: string
}

export default Select

0 comments on commit 6866864

Please sign in to comment.