Skip to content

Commit

Permalink
fix: avoid double clicking issue (#488)
Browse files Browse the repository at this point in the history
Fixes: #487
  • Loading branch information
Xstoudi authored May 26, 2023
1 parent 454dc7f commit a98a468
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/components/accordion/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import type { ReactElement, ReactNode, ReactFragment } from 'react';

import { useDoubleClick } from '../hooks/index';
import type {
ReactElement,
ReactNode,
ReactFragment,
MouseEvent as ReactMouseEvent,
} from 'react';
import { useCallback } from 'react';

import { useAccordionContext } from './AccordionContext';

Expand Down Expand Up @@ -61,10 +65,16 @@ export function Accordion(props: AccordionProps) {
Accordion.Item = function AccordionItem(props: AccordionItemProps) {
const { item, utils } = useAccordionContext(props.title, props.defaultOpened);

const onClickHandle = useDoubleClick({
onClick: utils.toggle,
onDoubleClick: utils.clear,
});
const onClickHandle = useCallback(
(event: ReactMouseEvent<HTMLButtonElement, MouseEvent>) => {
if (event.shiftKey) {
utils.clear();
} else {
utils.toggle();
}
},
[utils],
);

let displayable = false;

Expand All @@ -87,7 +97,7 @@ Accordion.Item = function AccordionItem(props: AccordionItemProps) {
display: 'flex',
alignItems: 'center',
width: '100%',
userSelect: 'text',
userSelect: 'none',
}}
css={styles.header}
>
Expand Down

0 comments on commit a98a468

Please sign in to comment.