diff --git a/src/Chip/Chip.test.jsx b/src/Chip/Chip.test.jsx index fd933621fbf..6a28153f822 100644 --- a/src/Chip/Chip.test.jsx +++ b/src/Chip/Chip.test.jsx @@ -77,5 +77,23 @@ describe('', () => { await userEvent.type(iconAfter, '{enter}'); expect(func).toHaveBeenCalled(); }); + it('onIconBeforeClick is triggered', async () => { + const func = jest.fn(); + render( + , + ); + const iconBefore = screen.getByTestId('icon-before'); + await userEvent.click(iconBefore); + expect(func).toHaveBeenCalled(); + }); + it('onIconBeforeKeyDown is triggered', async () => { + const func = jest.fn(); + render( + , + ); + const iconBefore = screen.getByTestId('icon-before'); + await userEvent.type(iconBefore, '{enter}'); + expect(func).toHaveBeenCalled(); + }); }); }); diff --git a/src/Chip/README.md b/src/Chip/README.md index 6497f9e7d3e..0fbcbc28f58 100644 --- a/src/Chip/README.md +++ b/src/Chip/README.md @@ -16,34 +16,99 @@ notes: | ## Basic Usage ```jsx live -
- New - New - New -
+ + New + New + ``` ## With Icon Before and After +### Basic Usage ```jsx live -
- New - console.log('Remove Chip')} - > - New - - console.log('Remove Chip')} - disabled - > - New - -
+ + New + console.log('onIconAfterClick')} + > + New 1 + + console.log('Remove Chip')} + > + New + + console.log('onIconBeforeClick')} + onIconAfterClick={() => console.log('onIconAfterClick')} + > + New + + console.log('onIconAfterClick')} + disabled + > + New + + +``` + +### Inverse Pallete + +```jsx live + + New + console.log('onIconAfterClick')} + > + New 1 + + console.log('Remove Chip')} + > + New + + console.log('onIconBeforeClick')} + onIconAfterClick={() => console.log('onIconAfterClick')} + > + New + + console.log('onIconAfterClick')} + disabled + > + New + + ``` diff --git a/src/Chip/__snapshots__/Chip.test.jsx.snap b/src/Chip/__snapshots__/Chip.test.jsx.snap index 4b706e50dbe..f1982430b7e 100644 --- a/src/Chip/__snapshots__/Chip.test.jsx.snap +++ b/src/Chip/__snapshots__/Chip.test.jsx.snap @@ -3,6 +3,10 @@ exports[` snapshots renders with props iconAfter 1`] = `
snapshots renders with props iconAfter 1`] = `
snapshots renders with props iconAfter 1`] = ` exports[` snapshots renders with props iconBefore 1`] = `
snapshots renders with props iconBefore 1`] = ` exports[` snapshots renders with props iconBefore and iconAfter 1`] = `
snapshots renders with props iconBefore and iconAfter 1`] = `
snapshots renders with props iconBefore and iconAfter 1`] = ` exports[` snapshots renders without props 1`] = `
) => ( -
- {iconBefore && ( -
- -
- )} +}: IChip, ref: ForwardedRef) => { + const [isSelected, setIsSelected] = useState(false); + + const handleClick = () => { + setIsSelected(!isSelected); + }; + + return (
- {children} -
- {iconAfter && ( + {iconBefore && ( +
+ {onIconBeforeClick ? ( + + ) : ( + + )} +
+ )}
- + {children}
- )} -
-)); + {iconAfter && ( +
+ {onIconAfterClick ? ( + + ) : ( + + )} +
+ )} +
+ ); +}); Chip.propTypes = { /** Specifies the content of the `Chip`. */ diff --git a/src/Chip/mixins.scss b/src/Chip/mixins.scss new file mode 100644 index 00000000000..5611132d101 --- /dev/null +++ b/src/Chip/mixins.scss @@ -0,0 +1,12 @@ +@mixin chip-outline($ring-color: $white, $distance-to-border: 0, $border-radius: 50%, $border-width: .125rem) { + &::before { + content: ""; + position: absolute; + top: $distance-to-border; + right: $distance-to-border; + bottom: $distance-to-border; + left: $distance-to-border; + border: solid $border-width $ring-color; + border-radius: $border-radius; + } +} diff --git a/src/SelectableBox/tests/SelectableBoxSet.test.jsx b/src/SelectableBox/tests/SelectableBoxSet.test.jsx index 934220403b3..e010d69d69b 100644 --- a/src/SelectableBox/tests/SelectableBoxSet.test.jsx +++ b/src/SelectableBox/tests/SelectableBoxSet.test.jsx @@ -68,10 +68,13 @@ describe('', () => { expect(screen.getByTestId('checkbox-set')).toBeInTheDocument(); }); it('renders with radio type if neither checkbox nor radio is passed', () => { + // eslint-disable-next-line no-console const originalError = console.error; + // eslint-disable-next-line no-console console.error = jest.fn(); render(); expect(screen.getByTestId('radio-set')).toBeInTheDocument(); + // eslint-disable-next-line no-console console.error = originalError; }); it('renders with radio type', () => {