@bitrise/bitkit 10.26.1 → 10.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Components/Dropdown/Dropdown.context.tsx +1 -1
- package/src/Components/Dropdown/Dropdown.test.tsx +42 -0
- package/src/Components/Dropdown/DropdownOption.tsx +9 -4
- package/src/Components/Table/Table.stories.tsx +1 -1
- package/src/Components/Table/Tr.tsx +4 -2
- package/src/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ type DropdownContext<T> = {
|
|
|
16
16
|
searchOnSubmit: () => void;
|
|
17
17
|
filter?: string;
|
|
18
18
|
activeIndex?: number | null;
|
|
19
|
-
getItemProps: (
|
|
19
|
+
getItemProps: (userProps?: React.HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const [DropdownContextProvider, useDropdownContext] = createContext<DropdownContext<unknown>>();
|
|
@@ -581,4 +581,46 @@ describe('Dropdown', () => {
|
|
|
581
581
|
expect(button).toHaveTextContent('Custom label');
|
|
582
582
|
});
|
|
583
583
|
});
|
|
584
|
+
|
|
585
|
+
describe('option onClick support', () => {
|
|
586
|
+
it('calls onClick handler on option', async () => {
|
|
587
|
+
const onChangeHandler = jest.fn();
|
|
588
|
+
const onClickHandler = jest.fn();
|
|
589
|
+
|
|
590
|
+
render(
|
|
591
|
+
<Dropdown onChange={onChangeHandler}>
|
|
592
|
+
<DropdownOption value="Test option 1">Test option 1</DropdownOption>
|
|
593
|
+
<DropdownOption value="Test option 2" onClick={onClickHandler}>
|
|
594
|
+
Test option 2
|
|
595
|
+
</DropdownOption>
|
|
596
|
+
</Dropdown>,
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
const button = await screen.findByRole('combobox');
|
|
600
|
+
await userEvent.click(button);
|
|
601
|
+
const option2 = await screen.findByRole('option', { name: 'Test option 2' });
|
|
602
|
+
await userEvent.click(option2);
|
|
603
|
+
expect(onClickHandler).toHaveBeenCalled();
|
|
604
|
+
expect(onChangeHandler).toHaveBeenCalled();
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
it("doesn't call onChange handler if option's onClick handler prevented it", async () => {
|
|
608
|
+
const onChangeHandler = jest.fn();
|
|
609
|
+
|
|
610
|
+
render(
|
|
611
|
+
<Dropdown onChange={onChangeHandler}>
|
|
612
|
+
<DropdownOption value="Test option 1">Test option 1</DropdownOption>
|
|
613
|
+
<DropdownOption value="Test option 2" onClick={(event) => event.preventDefault()}>
|
|
614
|
+
Test option 2
|
|
615
|
+
</DropdownOption>
|
|
616
|
+
</Dropdown>,
|
|
617
|
+
);
|
|
618
|
+
|
|
619
|
+
const button = await screen.findByRole('combobox');
|
|
620
|
+
await userEvent.click(button);
|
|
621
|
+
const option2 = await screen.findByRole('option', { name: 'Test option 2' });
|
|
622
|
+
await userEvent.click(option2);
|
|
623
|
+
expect(onChangeHandler).not.toHaveBeenCalled();
|
|
624
|
+
});
|
|
625
|
+
});
|
|
584
626
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode, useId } from 'react';
|
|
1
|
+
import { MouseEventHandler, ReactNode, useId } from 'react';
|
|
2
2
|
import { chakra } from '@chakra-ui/react';
|
|
3
3
|
import { cx } from '@chakra-ui/utils';
|
|
4
4
|
import Text from '../Text/Text';
|
|
@@ -9,8 +9,9 @@ export type DropdownOptionProps<T> = {
|
|
|
9
9
|
value?: T | null;
|
|
10
10
|
children?: ReactNode;
|
|
11
11
|
'aria-label'?: string;
|
|
12
|
+
onClick?: MouseEventHandler<HTMLElement>;
|
|
12
13
|
};
|
|
13
|
-
const DropdownOption = <T = string,>({ value = null, children, ...rest }: DropdownOptionProps<T>) => {
|
|
14
|
+
const DropdownOption = <T = string,>({ value = null, children, onClick, ...rest }: DropdownOptionProps<T>) => {
|
|
14
15
|
const { item } = useDropdownStyles();
|
|
15
16
|
const ctx = useDropdownContext<T | null>();
|
|
16
17
|
const { index } = rest as { index?: number };
|
|
@@ -30,8 +31,12 @@ const DropdownOption = <T = string,>({ value = null, children, ...rest }: Dropdo
|
|
|
30
31
|
)}
|
|
31
32
|
__css={item}
|
|
32
33
|
{...ctx.getItemProps({
|
|
33
|
-
onClick() {
|
|
34
|
-
|
|
34
|
+
onClick(event) {
|
|
35
|
+
onClick?.(event);
|
|
36
|
+
|
|
37
|
+
if (!event.defaultPrevented) {
|
|
38
|
+
ctx.onOptionSelected({ value, index, label: children });
|
|
39
|
+
}
|
|
35
40
|
},
|
|
36
41
|
})}
|
|
37
42
|
>
|
|
@@ -60,7 +60,7 @@ const Tr = forwardRef<TableRowProps, 'tr'>((props, ref) => {
|
|
|
60
60
|
<Td sx={css.expandTd}>
|
|
61
61
|
<IconButton
|
|
62
62
|
iconName="ChevronDown"
|
|
63
|
-
aria-label=
|
|
63
|
+
aria-label={isOpen ? 'Collapse row' : 'Expand row'}
|
|
64
64
|
onClick={onToggleClick}
|
|
65
65
|
size="small"
|
|
66
66
|
variant="tertiary"
|
|
@@ -76,7 +76,9 @@ const Tr = forwardRef<TableRowProps, 'tr'>((props, ref) => {
|
|
|
76
76
|
</ChakraTr>
|
|
77
77
|
<ChakraTr>
|
|
78
78
|
<Td colSpan={colSpan} paddingY="0" transform={isOpen ? 'none' : 'translateY(-1px)'}>
|
|
79
|
-
<Collapse in={isOpen}>
|
|
79
|
+
<Collapse in={isOpen} unmountOnExit>
|
|
80
|
+
{expandableContent}
|
|
81
|
+
</Collapse>
|
|
80
82
|
</Td>
|
|
81
83
|
</ChakraTr>
|
|
82
84
|
</>
|