Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustinMauroy committed Oct 28, 2023
1 parent 7ee462e commit 177009f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
7 changes: 1 addition & 6 deletions components/Common/ThemeToggle/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ beforeEach(() => {
mockCurrentTheme = 'light';
render(
<LocaleProvider>
<ThemeToggle onChange={toggleTheme} />
<ThemeToggle onClick={toggleTheme} />
</LocaleProvider>
);
toggle = screen.getByRole('button');
Expand All @@ -34,9 +34,4 @@ describe('ThemeToggle component', () => {
await userEvent.click(toggle);
expect(mockCurrentTheme).toBe('dark');
});

it('switch when press enter', async () => {
await userEvent.type(toggle, '{enter}');
expect(mockCurrentTheme).toBe('dark');
});
});
13 changes: 4 additions & 9 deletions components/Common/ThemeToggle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { MoonIcon, SunIcon } from '@heroicons/react/24/outline';
import { AccessibleIcon } from '@radix-ui/react-accessible-icon';
import type { FC } from 'react';
import type { FC, MouseEvent } from 'react';
import { useIntl } from 'react-intl';

import styles from './index.module.css';

type ThemeToggleProps = {
onChange: () => void;
onClick: (event: MouseEvent<HTMLButtonElement>) => void;
};

const ThemeToggle: FC<ThemeToggleProps> = ({ onChange }) => {
const ThemeToggle: FC<ThemeToggleProps> = ({ onClick }) => {
const intl = useIntl();

return (
<button
type="button"
onClick={onChange}
onKeyDown={onChange}
className={styles.themeToggle}
>
<button type="button" onClick={onClick} className={styles.themeToggle}>
<AccessibleIcon
label={intl.formatMessage({
id: 'components.header.buttons.toggleDarkMode',
Expand Down

0 comments on commit 177009f

Please sign in to comment.