Refactor collection creation UI (#6485)

* Iteration, before functional component

* Use react-hook-form, shared form for new and edit

* Avoid negative margin on input prefix

* Centered now default for modals
This commit is contained in:
Tom Moor
2024-02-03 11:23:25 -08:00
committed by GitHub
parent abaa56c8f1
commit 0a54227d97
38 changed files with 705 additions and 744 deletions

View File

@@ -48,6 +48,12 @@ export type Props = {
onChange?: (value: string | null) => void;
};
export interface InputSelectRef {
value: string | null;
focus: () => void;
blur: () => void;
}
interface InnerProps extends React.HTMLAttributes<HTMLDivElement> {
placement: Placement;
}
@@ -55,7 +61,7 @@ interface InnerProps extends React.HTMLAttributes<HTMLDivElement> {
const getOptionFromValue = (options: Option[], value: string | null) =>
options.find((option) => option.value === value);
const InputSelect = (props: Props) => {
const InputSelect = (props: Props, ref: React.RefObject<InputSelectRef>) => {
const {
value = null,
label,
@@ -122,6 +128,16 @@ const InputSelect = (props: Props) => {
{ capture: true }
);
React.useImperativeHandle(ref, () => ({
focus: () => {
buttonRef.current?.focus();
},
blur: () => {
buttonRef.current?.blur();
},
value: select.selectedValue,
}));
React.useEffect(() => {
previousValue.current = value;
select.setSelectedValue(value);
@@ -306,4 +322,4 @@ export const Positioner = styled(Position)`
}
`;
export default InputSelect;
export default React.forwardRef(InputSelect);