Skip to content

Commit 7643f0b

Browse files
refactor(MultiSelect): do not show multiple grid cols if entry amount is too small
1 parent 9b79602 commit 7643f0b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/input/select/MultiSelect.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function OptionList(p: OptionListProps) {
170170
role="listbox"
171171
aria-multiselectable="true"
172172
onKeyDown={handleKeyDown}
173-
class={classArr(p.innerClass ?? classesGridCols3xl + " gap-x-2 gap-y-1")}
173+
class={getInnerClass(options.length, p.innerClass)}
174174
>
175175
<For each={options}>
176176
{(option, index) => (
@@ -190,6 +190,16 @@ function OptionList(p: OptionListProps) {
190190
)
191191
}
192192

193+
function getInnerClass(optionAmount: number, innerClass?: string): string {
194+
if (innerClass) return innerClass
195+
if (optionAmount <= 0) return ""
196+
const base = " gap-x-2 gap-y-1"
197+
if (optionAmount <= 5) return "grid grid-cols-1" + base
198+
if (optionAmount <= 9) return "grid grid-cols-2" + base
199+
if (optionAmount > 9) return classesGridCols3xl + base
200+
return ""
201+
}
202+
193203
interface ListOptionProps extends HasId, MultiselectOptionState {
194204
index: number
195205
focusedIndex: number

0 commit comments

Comments
 (0)