Skip to content

Commit 1e8bb4c

Browse files
committed
fix: form multiselect field scrolling not working
1 parent c472308 commit 1e8bb4c

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

frontend/src/components/Form/MultiSelectField.jsx

+20-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Fragment, useEffect, useState } from 'react';
44
import 'react-dates/initialize';
55
import 'react-dates/lib/css/_datepicker.css';
66
import { usePopper } from 'react-popper';
7-
import { FixedSizeList as List } from 'react-window';
87
import { ReactComponent as FormSelectSearchCloseIcon } from '../../assets/images/svg/form-select-search-close-icon.svg';
98
import { ReactComponent as FormSelectDropdownIcon } from '../../assets/images/svg/form-select-dropdown-icon.svg';
109
import { ReactComponent as RemoveOptionIcon } from '../../assets/images/svg/remove-option-icon.svg';
@@ -108,7 +107,10 @@ const MultiSelectField = ({
108107
style={styles['popper']}
109108
{...attributes['popper']}
110109
>
111-
<Listbox.Options data-cy="multi_select_values" className="absolute z-[1] h-fit max-h-96 w-full overflow-y-auto border bg-white px-[8px] py-[12px] font-lato text-base ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm">
110+
<Listbox.Options
111+
data-cy="multi_select_values"
112+
className="absolute z-[1] h-fit max-h-96 w-full overflow-y-auto border bg-white px-[8px] py-[12px] font-lato text-base ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm"
113+
>
112114
{optionsData?.length > 10 ? (
113115
<div className="relative mb-4">
114116
<input
@@ -130,50 +132,40 @@ const MultiSelectField = ({
130132
</div>
131133
) : null}
132134

133-
<List
134-
height={
135-
filteredOptions.length < 10
136-
? filteredOptions.length * 40
137-
: 300
138-
}
139-
itemCount={filteredOptions.length}
140-
itemSize={40}
141-
itemData={filteredOptions}
142-
className="complete-hidden-scroll-style"
143-
>
144-
{({ index, style }) => (
135+
{/* Replaced the react-window List with a normal map */}
136+
<Listbox.Options className="space-y-2">
137+
{filteredOptions.map((option, index) => (
145138
<Listbox.Option
146139
key={index}
147-
style={style}
148140
className={({ active }) =>
149141
`relative flex cursor-default select-none items-center gap-[12px] p-2 ${
150142
active ? '' : ''
151143
}`
152144
}
153-
value={filteredOptions[index]}
154-
disabled={filteredOptions[index].unavailable || false}
145+
value={option}
146+
disabled={option.unavailable || false}
155147
>
156148
<span className="flex items-center">
157149
<FormMultiSelectCheckIcon
158150
className={`${
159-
value.indexOf(filteredOptions[index].id) >= 0
151+
value.indexOf(option.id) >= 0
160152
? 'text-[#000000]'
161153
: 'text-[#eff3f4]'
162154
} `}
163155
/>
164156
</span>
165157
<span
166158
className={`block truncate font-lato ${
167-
filteredOptions[index].unavailable || false
159+
option.unavailable || false
168160
? 'opacity-50'
169161
: 'cursor-pointer'
170162
}`}
171163
>
172-
{filteredOptions[index].label}
164+
{option.label}
173165
</span>
174166
</Listbox.Option>
175-
)}
176-
</List>
167+
))}
168+
</Listbox.Options>
177169
</Listbox.Options>
178170
</Transition>
179171
</div>
@@ -200,7 +192,12 @@ const MultiSelectField = ({
200192
</div>
201193

202194
{meta.touched && meta.error ? (
203-
<div data-cy="error_message" className="font-lato text-[12px] text-[#cc3300]">{meta.error}</div>
195+
<div
196+
data-cy="error_message"
197+
className="font-lato text-[12px] text-[#cc3300]"
198+
>
199+
{meta.error}
200+
</div>
204201
) : null}
205202
</div>
206203
);

0 commit comments

Comments
 (0)