diff --git a/packages/react/src/components/Chips/Chips.tsx b/packages/react/src/components/Chips/Chips.tsx index 3510a2c9..c1ce852e 100644 --- a/packages/react/src/components/Chips/Chips.tsx +++ b/packages/react/src/components/Chips/Chips.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from 'react'; +import { Children, Fragment, useRef, useState } from 'react'; import { ChipsProps } from './Chips.types'; @@ -63,15 +63,21 @@ export const Chips = (inProps: ChipsProps) => { if ( totalWidth + - columnGap + chipWidth + (!open && index < chips.length - 1 && lineCount >= maxLines ? columnGap + buttonWidth : 0) >= containerWidth ) { lineCount += 1; - totalWidth = chipWidth; + totalWidth = chipWidth + columnGap; + + if ( + totalWidth + (!open && index < chips.length - 1 && lineCount >= maxLines ? buttonWidth : 0) >= + containerWidth + ) { + lineCount += 1; + } } else { - totalWidth += columnGap + chipWidth; + totalWidth += chipWidth + columnGap; } if (!open && lineCount > maxLines) { @@ -91,21 +97,42 @@ export const Chips = (inProps: ChipsProps) => { onResize(); }, [open]); + const button = ( + + ); + return (
- {children} - + {Children.map(children, (child: any, i: number) => { + const isLastChild = i === Children.count(children) - 1; + + if (open && isLastChild) { + return ( +
+ {child} + {button} +
+ ); + } + + return ( + + {child} + {!open && isLastChild && button} + + ); + })}
); }; diff --git a/packages/theme/lib/components/_chips.scss b/packages/theme/lib/components/_chips.scss index e448c456..14e9d707 100644 --- a/packages/theme/lib/components/_chips.scss +++ b/packages/theme/lib/components/_chips.scss @@ -7,6 +7,13 @@ gap: 8px; position: relative; + &__wrapper { + display: flex; + flex-wrap: wrap; + gap: inherit; + min-width: 0; + } + &__button { border-radius: 1000px;