Skip to content

Commit

Permalink
fix: custom menu item renderer on select
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhu-Kathiresan committed May 27, 2022
1 parent cfc8d26 commit c0b029f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions example/src/SelectComponent.js
Expand Up @@ -112,6 +112,7 @@ export default function SelectComponent() {
searchable
label={`${options.label} - Async version`}
onSearch={handleSearch}
customMenuItemRender={(item) => <span style={{ color: 'teal' }}>{item.name}</span>}
/>
</div>
<div className='col-lg-3'>
Expand Down
2 changes: 2 additions & 0 deletions src/Select/helpers.ts
Expand Up @@ -14,6 +14,8 @@ export const stringify = (value: object) => JSON.stringify(value)
export const isEqual = (obj1: object = {}, obj2: object = {}) => stringify(obj1) === stringify(obj2)

function isMatch(input: string, string: string, props: SelectProps) {
if (props.async) return true

let searchStr = input
let str = string

Expand Down
1 change: 1 addition & 0 deletions src/Select/props.ts
Expand Up @@ -28,6 +28,7 @@ export interface SelectProps extends InputProps {
animate?: boolean
transitionDuration?: number
onMenuItemRender?: Function
customMenuItemRender?: Function
dropup?: boolean
flip?: boolean
containerClass?: string
Expand Down
9 changes: 3 additions & 6 deletions src/Select/utils.ts
Expand Up @@ -49,10 +49,7 @@ export const getStateFromProps = (props: SelectProps): SelectState => {

let stateSelected = optionsMap([...selected], props)

// selected = optionsMap([...selected], props)

if (!multiple && stateSelected && stateSelected.length) {
// selected = [...selected].shift() || {}
let [first] = selected
value = first[labelKey]
}
Expand Down Expand Up @@ -103,19 +100,19 @@ export const constructMenuProps = (props: any) => {
}

export const optionsMap = (options: Array<OptionProps | string>, props: SelectProps): Array<OptionProps> => {
let { labelKey, onMenuItemRender } = props
let { labelKey, customMenuItemRender } = props
return options.map(option => {
if (typeof option === 'string') {
return {
[labelKey]: option,
__label: onMenuItemRender ? onMenuItemRender(option) : option,
__label: customMenuItemRender ? customMenuItemRender(option) : option,
[ACTUAL_VALUE]: option
}
} else {
return {
...option,
[labelKey]: option[labelKey],
__label: onMenuItemRender ? onMenuItemRender(option) : option[labelKey],
__label: customMenuItemRender ? customMenuItemRender(option) : option[labelKey],
[ACTUAL_VALUE]: {
...option
}
Expand Down

0 comments on commit c0b029f

Please sign in to comment.