Skip to content

Commit e749529

Browse files
fix: multi value draggable/sortable pills (#6500)
1 parent 4a51f4d commit e749529

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

packages/ui/src/elements/ReactSelect/MultiValue/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ import { useDraggableSortable } from '../../DraggableSortable/useDraggableSortab
1010
import './index.scss'
1111

1212
const baseClass = 'multi-value'
13+
14+
export function generateMultiValueDraggableID(optionData, valueFunction) {
15+
return typeof valueFunction === 'function' ? valueFunction(optionData) : optionData.value
16+
}
1317
export const MultiValue: React.FC<MultiValueProps<Option>> = (props) => {
1418
const {
1519
className,
16-
data: { value },
20+
data,
1721
innerProps,
1822
isDisabled,
1923
// @ts-expect-error // TODO Fix this - moduleResolution 16 breaks our declare module
20-
selectProps: { customProps: { disableMouseDown } = {}, isSortable } = {},
24+
selectProps: { customProps: { disableMouseDown } = {}, getOptionValue, isSortable } = {},
2125
} = props
2226

2327
const { attributes, isDragging, listeners, setNodeRef, transform } = useDraggableSortable({
24-
id: typeof value === 'string' && value.toString(),
28+
id: generateMultiValueDraggableID(data, getOptionValue),
2529
disabled: !isSortable,
2630
})
2731

packages/ui/src/elements/ReactSelect/index.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { DraggableSortable } from '../DraggableSortable/index.js'
1616
import { ClearIndicator } from './ClearIndicator/index.js'
1717
import { Control } from './Control/index.js'
1818
import { DropdownIndicator } from './DropdownIndicator/index.js'
19-
import { MultiValue } from './MultiValue/index.js'
19+
import { MultiValue, generateMultiValueDraggableID } from './MultiValue/index.js'
2020
import { MultiValueLabel } from './MultiValueLabel/index.js'
2121
import { MultiValueRemove } from './MultiValueRemove/index.js'
2222
import { SingleValue } from './SingleValue/index.js'
@@ -172,18 +172,19 @@ const SelectAdapter: React.FC<ReactSelectAdapterProps> = (props) => {
172172
}
173173

174174
const SortableSelect: React.FC<ReactSelectAdapterProps> = (props) => {
175-
const { onChange, value } = props
175+
const { getOptionValue, onChange, value } = props
176176

177-
let ids: string[] = []
178-
if (value)
179-
ids = Array.isArray(value)
180-
? value.map((item) => item?.id ?? `${item?.value}`)
181-
: [value?.id || `${value?.value}`]
177+
let draggableIDs: string[] = []
178+
if (value) {
179+
draggableIDs = (Array.isArray(value) ? value : [value]).map((optionValue) => {
180+
return generateMultiValueDraggableID(optionValue, getOptionValue)
181+
})
182+
}
182183

183184
return (
184185
<DraggableSortable
185186
className="react-select-container"
186-
ids={ids}
187+
ids={draggableIDs}
187188
onDragEnd={({ moveFromIndex, moveToIndex }) => {
188189
let sorted = value
189190
if (value && Array.isArray(value)) {

packages/ui/src/fields/Relationship/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ const RelationshipField: React.FC<RelationshipFieldProps> = (props) => {
496496
disabled={readOnly || formProcessing || drawerIsOpen}
497497
filterOption={enableWordBoundarySearch ? filterOption : undefined}
498498
getOptionValue={(option) => {
499+
if (!option) return undefined
499500
return hasMany && Array.isArray(relationTo)
500501
? `${option.relationTo}_${option.value}`
501502
: option.value

0 commit comments

Comments
 (0)