Skip to content

Commit 882918f

Browse files
fix(select/select-hint): fallback tooltip shows children
Using @kevin940726's workaround for vercel/next.js#7906
1 parent cbecc3f commit 882918f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

components/select/select-hint.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import React from 'react';
1+
import { createContext, useContext } from 'react';
22
import { TooltipProps } from '@rmwc/tooltip';
33
import dynamic from 'next/dynamic';
44
import useTranslation from 'next-translate/useTranslation';
55

6-
const Tooltip = dynamic<TooltipProps>(() =>
7-
import('@rmwc/tooltip').then((m) => m.Tooltip)
6+
// Temporary workaround for not being able to access the `children` prop in the
7+
// fallback loading component (while the `Tooltip` is being dynamically loaded).
8+
// @see {@link https://github.com/vercel/next.js/issues/7906}
9+
const TooltipLoadingContext = createContext<JSX.Element>(<></>);
10+
11+
const Tooltip = dynamic<TooltipProps>(
12+
() => import('@rmwc/tooltip').then((m) => m.Tooltip),
13+
{ loading: () => useContext(TooltipLoadingContext) }
814
);
915

1016
interface SelectHintProps {
@@ -18,8 +24,10 @@ export default function SelectHint({
1824
}: SelectHintProps): JSX.Element {
1925
const { t } = useTranslation();
2026
return (
21-
<Tooltip content={t('common:shift-click')} align='topRight' open={open}>
22-
{children}
23-
</Tooltip>
27+
<TooltipLoadingContext.Provider value={children}>
28+
<Tooltip content={t('common:shift-click')} align='topRight' open={open}>
29+
{children}
30+
</Tooltip>
31+
</TooltipLoadingContext.Provider>
2432
);
2533
}

0 commit comments

Comments
 (0)