Fix: select add portalRef instead of modalContextId

This commit is contained in:
Johannes Kirschbauer
2025-01-09 10:15:29 +01:00
parent b02dc42b0a
commit b73de90487
2 changed files with 84 additions and 62 deletions

View File

@@ -5,6 +5,7 @@ import {
type JSX, type JSX,
For, For,
createMemo, createMemo,
Accessor,
} from "solid-js"; } from "solid-js";
import { Portal } from "solid-js/web"; import { Portal } from "solid-js/web";
import { useFloating } from "../base"; import { useFloating } from "../base";
@@ -46,11 +47,12 @@ interface SelectInputpProps {
placeholder?: string; placeholder?: string;
multiple?: boolean; multiple?: boolean;
loading?: boolean; loading?: boolean;
dialogContextId?: string; portalRef?: Accessor<HTMLElement | null>;
} }
export function SelectInput(props: SelectInputpProps) { export function SelectInput(props: SelectInputpProps) {
const dialogContext = useContext(props.dialogContextId); const dialogContext = (dialogContextId?: string) =>
useContext(dialogContextId);
const _id = createUniqueId(); const _id = createUniqueId();
@@ -228,7 +230,11 @@ export function SelectInput(props: SelectInputpProps) {
} }
/> />
<Portal mount={dialogContext.contentRef?.() || document.body}> <Portal
mount={
props.portalRef ? props.portalRef() || document.body : document.body
}
>
<div <div
id={_id} id={_id}
popover popover

View File

@@ -11,6 +11,7 @@ import { StepProps } from "./hardware-step";
import { SelectInput } from "@/src/Form/fields/Select"; import { SelectInput } from "@/src/Form/fields/Select";
import { Typography } from "@/src/components/Typography"; import { Typography } from "@/src/components/Typography";
import { Group } from "@/src/components/group"; import { Group } from "@/src/components/group";
import { useContext } from "corvu/dialog";
export interface DiskValues extends FieldValues { export interface DiskValues extends FieldValues {
placeholders: { placeholders: {
@@ -44,14 +45,22 @@ export const DiskStep = (props: StepProps<DiskValues>) => {
}, },
})); }));
const modalContext = useContext();
return ( return (
<>
<Form <Form
onSubmit={handleSubmit} onSubmit={handleSubmit}
class="flex flex-col gap-6" class="flex flex-col gap-6"
noValidate={false} noValidate={false}
> >
<div class="max-h-[calc(100vh-20rem)] overflow-y-scroll">
<div class="flex h-full flex-col gap-6 p-4">
<span class="flex flex-col gap-4"> <span class="flex flex-col gap-4">
<Field name="schema" validate={required("Schema must be provided")}> <Field
name="schema"
validate={required("Schema must be provided")}
>
{(field, fieldProps) => ( {(field, fieldProps) => (
<> <>
<Typography <Typography
@@ -60,7 +69,9 @@ export const DiskStep = (props: StepProps<DiskValues>) => {
weight="bold" weight="bold"
class="capitalize" class="capitalize"
> >
{(field.value || "No schema selected").split("-").join(" ")} {(field.value || "No schema selected")
.split("-")
.join(" ")}
</Typography> </Typography>
<Typography <Typography
hierarchy="body" hierarchy="body"
@@ -75,7 +86,8 @@ export const DiskStep = (props: StepProps<DiskValues>) => {
</Field> </Field>
</span> </span>
<Group> <Group>
{props.initial?.initialized && "Disk has been initialized already"} {props.initial?.initialized &&
"Disk has been initialized already"}
<Field <Field
name="placeholders.mainDisk" name="placeholders.mainDisk"
validate={ validate={
@@ -100,11 +112,15 @@ export const DiskStep = (props: StepProps<DiskValues>) => {
placeholder="Select a disk" placeholder="Select a disk"
selectProps={fieldProps} selectProps={fieldProps}
required={!props.initial?.initialized} required={!props.initial?.initialized}
portalRef={modalContext.contentRef}
/> />
)} )}
</Field> </Field>
</Group> </Group>
</div>
</div>
{props.footer} {props.footer}
</Form> </Form>
</>
); );
}; };