fix: admin: multiselection inputs (like countries and accounts) were scrolling to the top after each selection

Massimo Melina committed Mar 6, 2026 at 00:45 UTC dc6d1680c784e5e13e44a96f4fc778de449496ca
1 file changed +7 -5
mui-grid-form/SelectField.ts
+7 -5
@@ -1,6 +1,6 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 -import { createElement as h, Fragment, ReactNode, useId, useMemo } from 'react'
3 +import { createElement as h, Fragment, ReactNode, useId, useMemo, useCallback } from 'react'
4 import { FieldProps } from '.'
5 import {
6 FormControl, FormControlLabel, FormLabel, MenuItem, Radio, InputLabel, Select, LinearProgress,
@@ -99,10 +99,13 @@ export function MultiSelectField<T>({ renderOption, ...props }: MultiSelectField
99 !isMobile && normalizedOptions?.length! > 20 && h(Box, {
100 sx: { float: 'right' }, fontSize: 'small', width: '8em', textAlign: 'right', marginRight: '.5em'
101 }, "ⓘ You can type the name"),
102 - normalizedOptions?.length! > 1 && h(Button, {
102 + h(Button, {
103 size: 'small',
104 - sx: { ml: 1 },
105 - ref: x => x && Object.assign(x, { role: undefined }) && setTimeout(() => x.focus()), // cancel the role=option on this
104 + sx: { ml: 1, display: normalizedOptions?.length! > 1 ? undefined : 'none' },
105 + ref: useCallback((x: HTMLButtonElement | null) =>
106 + x && Object.assign(x, { role: undefined }) // cancel the role=option on this
107 + && setTimeout(() => x.focus()),
108 + []),
109 onClickCapture(event) {
110 event.stopPropagation()
111 onChange(isEmpty ? normalizedOptions!.map(x => x.value) : [], { was: value, event })
@@ -158,4 +161,3 @@ export function RadioField<T>({ label, options, value, onChange }: FieldProps<T>
161 })
162 )
163 }
161 -