New Experience with Next.js and Tailwind CSS
Exploring the next/font Package
Delving into the realm of the new next/font
package has been quite interesting. Following the tutorial provided by Next.js made the setup process smooth sailing. I've incorporated both Inter and a custom local typeface named App Takeoff into my project. To seamlessly integrate these typefaces, I've leveraged Tailwind CSS, assigning Inter to font-sans
and App Takeoff to font-display
.
A Minor Glitch in the System
After rigorous testing across various files, it appears that everything is functioning flawlessly except within my Modal
component. (Refer to the Helpful Update section below for insights on why the issue arises specifically in the Modal
component.)
An Illustrative Example
index.tsx
https://i.sstatic.net/8MyTU.png
modal.tsx via index.tsx
https://i.sstatic.net/YrMVA.png
Although the typefaces function seamlessly outside the modal element, they encounter a glitch when embedded within it.
Key Code Snippets:
// app.tsx
import '@/styles/globals.css'
import type { AppProps } from 'next/app'
import { Inter } from 'next/font/google'
const inter = Inter({
subsets: ['latin'],
variable: '--font-inter'
})
import localFont from 'next/font/local'
const appTakeoff = localFont({
src: [
{
path: '../fonts/app-takeoff/regular.otf',
weight: '400',
style: 'normal'
},
// additional font paths
],
variable: '--font-app-takeoff'
})
// remaining code snippet continues...
// modal.tsx
import type { FunctionComponent } from 'react'
// more import statements...
const Modal: FunctionComponent<ModalProps> = ({ trigger, place = 'bottom', className, addClass, children }) => {
// specific functions for modal handling
return (
<>
{/* main functionality of the modal */}
</>
)
}
export default Modal
I trust this information provides clarity on the issue at hand. Feel free to reach out if further details are required.
Valuable Insight
Credit goes to Jonathan Wieben for shedding light on the root cause behind the malfunction (See Explanation). The essence lies in the scope of applied styles and the utilization of React's Portal
component by Headless UI. Any suggestions on altering where the Portal
renders or adjusting the style scope would be greatly appreciated. While Jonathan Wieben proposed a solution, my experimentation indicates that it may not align well with Tailwind CSS.