As I delve into a Next.js project, my goal is to use Tailwind CSS to craft an interface featuring a sidebar on the left, a header at the top, and a main content area. However, an issue has surfaced where users can over-scroll, leading to a blank space appearing at the bottom of the page—this seems to be exacerbated when using the shadcn/ui switch component.
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
} from "@/components/ui/form"
import { Switch } from "@/components/ui/switch"
const FormSchema = z.object({
marketing_emails: z.boolean().default(false).optional(),
security_emails: z.boolean(),
})
export default function Home() {
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
security_emails: true,
},
})
function onSubmit(data: z.infer<typeof FormSchema>) {
console.log(data)
}
return (
<div className="flex h-screen">
{/* Sidebar */}
<div className="w-64 bg-gray-800 text-white p-4">
<div className="bg-red-500 h-full">
{/* Sidebar Content */}
</div>
</div>
{/* Main Content */}
<div className="flex-1 flex flex-col overflow-hidden">
{/* Header */}
<div className="bg-white shadow p-4">
<div className="bg-green-500 h-12">
{/* Header Content */}
</div>
</div>
{/* Main */}
<div className="flex-1 overflow-y-auto p-4">
<div className="bg-blue-500 h-full mb-4">
<div className={"h-72 bg-yellow-200"}>
<p>Coming soon</p>
</div>
<div className={"h-72 bg-orange-200"}>
<p>Coming soon</p>
</div>
<div className={"h-72 bg-purple-50"}>
<p>Coming soon</p>
</div>
<div className={"h-72 bg-blue-200"}>
<p>Coming soon</p>
</div>
<div className={"h-72 bg-pink-200"}>
<p>Coming soon</p>
</div>
<div className={"bg-green-200 h-72"}>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="w-full space-y-6">
<div>
<h3 className="mb-4 text-lg font-medium">Email Notifications</h3>
<div className="space-y-4">
<FormField
control={form.control}
name="marketing_emails"
render={({field}) => (
<FormItem
className="flex flex-row items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel className="text-base">
Marketing emails
</FormLabel>
<FormDescription>
Receive emails about new products, features, and more.
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</FormItem>
)}
/>
<FormField
control={form.control}
name="security_emails"
render={({field}) => (
<FormItem
className="flex flex-row items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel className="text-base">Security emails</FormLabel>
<FormDescription>
Receive emails about your account security.
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
disabled
aria-readonly
/>
</FormControl>
</FormItem>
)}
/>
</div>
</div>
<Button type="submit">Submit</Button>
</form>
</Form>
</div>
</div>
</div>
</div>
</div>
)
}
This code block serves as a demonstration only
https://i.sstatic.net/Mb6IkupB.png
The white space beneath the green box indicates the overscrolling issue