Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust optins columns #1093

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/ocean-core/src/components/_chips.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
padding: $spacing-inset-xxs 0;
position: absolute;
top: 38px;
width: auto;

&--content {
align-items: flex-start;
Expand All @@ -95,14 +96,18 @@

&--content--columns-2 {
display: grid;
grid-column-gap: 20px;
grid-template-columns: repeat(2, 1fr);
width: 296px;
min-width: 296px;
width: auto;
}

&--content--columns-3 {
display: grid;
grid-column-gap: 20px;
grid-template-columns: repeat(3, 1fr);
width: 436px;
min-width: 436px;
width: auto;
}

&::-webkit-scrollbar {
Expand All @@ -120,6 +125,7 @@
gap: $spacing-inline-xxs;
min-height: 40px;
padding: $spacing-stack-xxs 12px;
text-wrap: nowrap;
width: 100%;
}

Expand Down
9 changes: 6 additions & 3 deletions packages/ocean-react/src/Chips/Chips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IChips {
initialCounter?: number;
onClick?: () => void;
onChange?: (value: ChipValue[] | ChipValue) => void;
onClose?: () => void;
}

const Chips: React.FunctionComponent<IChips> = ({
Expand All @@ -32,6 +33,7 @@ const Chips: React.FunctionComponent<IChips> = ({
initialCounter,
onClick,
onChange,
onClose,
}) => {
const wrapperRef = useRef<HTMLDivElement>(null);
const [counter, setCounter] = React.useState<number>(0);
Expand All @@ -46,6 +48,8 @@ const Chips: React.FunctionComponent<IChips> = ({
if (wrapperRef.current && !wrapperRef.current.contains(target)) {
setSelectionIsOpen(false);
}

if (onClose) onClose();
}

useEffect(() => {
Expand All @@ -54,6 +58,7 @@ const Chips: React.FunctionComponent<IChips> = ({
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [wrapperRef]);

const handleClickChips = () => {
Expand Down Expand Up @@ -117,9 +122,7 @@ const Chips: React.FunctionComponent<IChips> = ({
const filterOptions = () => {
setSelectionIsOpen(false);

if (onChange) {
onChange(selectedOptions);
}
if (onClose) onClose();
};

return (
Expand Down
23 changes: 13 additions & 10 deletions packages/ocean-react/src/Chips/__tests__/Chips.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import Chips from '../Chips';
interface ISetup {
handleClick?: () => void;
handleChange?: () => void;
handleClose?: () => void;
}

const multiChoiceSetup = ({ handleClick, handleChange }: ISetup) => {
const multiChoiceSetup = ({
handleClick,
handleChange,
handleClose,
}: ISetup) => {
const options = [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
Expand All @@ -22,6 +27,7 @@ const multiChoiceSetup = ({ handleClick, handleChange }: ISetup) => {
options={options}
onClick={handleClick}
onChange={handleChange}
onClose={handleClose}
filterLabel="Test Filter"
clearLabel="Test Clear"
multiChoice
Expand Down Expand Up @@ -184,19 +190,14 @@ describe('Chips', () => {
});

test('checks filter options button', async () => {
const handleChange = jest.fn();
multiChoiceSetup({ handleChange });
const handleClose = jest.fn();
multiChoiceSetup({ handleClose });

await clickInOption('Option 1');

fireEvent.click(screen.getByText('Test Filter'));

expect(handleChange).toHaveBeenCalledWith([
{
label: 'Option 1',
value: '1',
},
]);
expect(handleClose).toHaveBeenCalledTimes(1);

expect(() => screen.getByTestId('ods-chips-option')).toThrow(
'Unable to find an element'
Expand All @@ -205,7 +206,8 @@ describe('Chips', () => {

test('checks click outside', async () => {
const handleClick = jest.fn();
multiChoiceSetup({ handleClick });
const handleClose = jest.fn();
multiChoiceSetup({ handleClick, handleClose });

expect(handleClick).toHaveBeenCalled();
expect(screen.getByTestId('ods-chips-option')).toBeInTheDocument();
Expand All @@ -215,6 +217,7 @@ describe('Chips', () => {
document.dispatchEvent(addEvent);
});

expect(handleClose).toHaveBeenCalledTimes(1);
expect(() => screen.getByTestId('ods-chips-option')).toThrow(
'Unable to find an element'
);
Expand Down
1 change: 1 addition & 0 deletions packages/ocean-react/src/Chips/stories/Chips.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ If that's not sufficient, you can check the [implementation of the component](ht
],
onClick: () => null,
onChange: () => null,
onClose: () => null,
}}
argTypes={{
label: {
Expand Down
Loading