Skip to content

Commit ecc14a6

Browse files
committed
fix(lib): 🐛 fix a problem where theme selector was not accessible
mantine Menu allows for keyboard navigation with the dropdown contents
1 parent 953755b commit ecc14a6

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

packages/lib/src/components/Header/components/ThemeSelector/ThemeSelector.tsx

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@
1717
* along with Essencium Frontend. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
import {
21-
ActionIcon,
22-
Group,
23-
Popover,
24-
PopoverDropdown,
25-
PopoverTarget,
26-
Text,
27-
useMantineColorScheme,
28-
} from '@mantine/core'
20+
import { ActionIcon, Menu, useMantineColorScheme } from '@mantine/core'
2921
import { IconDeviceLaptop, IconMoon, IconSun } from '@tabler/icons-react'
3022
import { useTranslation } from 'next-i18next'
3123
import { type JSX } from 'react'
@@ -49,8 +41,8 @@ export function ThemeSelector(): JSX.Element {
4941
const isAutoMode = colorScheme === COLOR_SCHEME.AUTO
5042

5143
return (
52-
<Popover width={130} position="bottom" withArrow>
53-
<PopoverTarget>
44+
<Menu width={130} position="bottom" withArrow>
45+
<Menu.Target>
5446
<ActionIcon
5547
variant="subtle"
5648
className="hover:bg-gray-50 dark:hover:bg-gray-900"
@@ -59,10 +51,10 @@ export function ThemeSelector(): JSX.Element {
5951
>
6052
{isLightMode ? <IconSun /> : <IconMoon />}
6153
</ActionIcon>
62-
</PopoverTarget>
54+
</Menu.Target>
6355

64-
<PopoverDropdown className="p-0 shadow-sm">
65-
<Group
56+
<Menu.Dropdown>
57+
<Menu.Item
6658
onClick={() => {
6759
setColorScheme(COLOR_SCHEME.LIGHT)
6860
}}
@@ -72,13 +64,12 @@ export function ThemeSelector(): JSX.Element {
7264
!isAutoMode &&
7365
'text-primary-600 dark:text-primary-200 bg-gray-50 dark:bg-gray-900',
7466
)}
67+
leftSection={<IconSun className="size-5" />}
7568
>
76-
<IconSun className="size-5" />
69+
{t('header.themeToggle.lightMode')}
70+
</Menu.Item>
7771

78-
<Text className="text-sm">{t('header.themeToggle.lightMode')}</Text>
79-
</Group>
80-
81-
<Group
72+
<Menu.Item
8273
onClick={() => {
8374
setColorScheme(COLOR_SCHEME.DARK)
8475
}}
@@ -88,13 +79,12 @@ export function ThemeSelector(): JSX.Element {
8879
!isAutoMode &&
8980
'text-primary-600 dark:text-primary-200 bg-gray-50 dark:bg-gray-900',
9081
)}
82+
leftSection={<IconMoon className="size-5" />}
9183
>
92-
<IconMoon className="size-5" />
93-
94-
<Text className="text-sm">{t('header.themeToggle.darkMode')}</Text>
95-
</Group>
84+
{t('header.themeToggle.darkMode')}
85+
</Menu.Item>
9686

97-
<Group
87+
<Menu.Item
9888
onClick={() => {
9989
clearColorScheme()
10090
}}
@@ -104,12 +94,11 @@ export function ThemeSelector(): JSX.Element {
10494
isAutoMode &&
10595
'text-primary-600 dark:text-primary-200 bg-gray-50 dark:bg-gray-900',
10696
)}
97+
leftSection={<IconDeviceLaptop className="size-5" />}
10798
>
108-
<IconDeviceLaptop className="size-5" />
109-
110-
<Text className="text-sm">{t('header.themeToggle.systemMode')}</Text>
111-
</Group>
112-
</PopoverDropdown>
113-
</Popover>
99+
{t('header.themeToggle.systemMode')}
100+
</Menu.Item>
101+
</Menu.Dropdown>
102+
</Menu>
114103
)
115104
}

0 commit comments

Comments
 (0)