Fix issue where the window would scroll to and hilight custom items in the select box
This commit is contained in:
1 parent
4e50535478
commit
733e14cb58
1 file changed
+4
-1
@@ -326,6 +326,7 @@ export const CreatableSelectInput = (props: CreatableSelectInputProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [isCustom, setIsCustom] = React.useState(!isInOptions && !!value);
|
const [isCustom, setIsCustom] = React.useState(!isInOptions && !!value);
|
||||||
|
const customInputRef = React.useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
// Build select options with "Custom" at the top
|
// Build select options with "Custom" at the top
|
||||||
const customOption: SelectOption = { value: CUSTOM_SELECT_VALUE, label: 'Custom' };
|
const customOption: SelectOption = { value: CUSTOM_SELECT_VALUE, label: 'Custom' };
|
||||||
@@ -386,6 +387,8 @@ export const CreatableSelectInput = (props: CreatableSelectInputProps) => {
|
|||||||
if (val === CUSTOM_SELECT_VALUE) {
|
if (val === CUSTOM_SELECT_VALUE) {
|
||||||
setIsCustom(true);
|
setIsCustom(true);
|
||||||
onChange('');
|
onChange('');
|
||||||
|
// focus the custom input only when the user actively selects "Custom"
|
||||||
|
requestAnimationFrame(() => customInputRef.current?.focus());
|
||||||
} else {
|
} else {
|
||||||
setIsCustom(false);
|
setIsCustom(false);
|
||||||
onChange(val);
|
onChange(val);
|
||||||
@@ -396,13 +399,13 @@ export const CreatableSelectInput = (props: CreatableSelectInputProps) => {
|
|||||||
</div>
|
</div>
|
||||||
{isCustom && (
|
{isCustom && (
|
||||||
<input
|
<input
|
||||||
|
ref={customInputRef}
|
||||||
type="text"
|
type="text"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={e => onChange(e.target.value)}
|
onChange={e => onChange(e.target.value)}
|
||||||
className={`${inputClasses} flex-1 min-w-0`}
|
className={`${inputClasses} flex-1 min-w-0`}
|
||||||
placeholder={props.placeholder ?? 'Enter custom value'}
|
placeholder={props.placeholder ?? 'Enter custom value'}
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
autoFocus
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user