Skip to content

Commit c1032a0

Browse files
committed
fix(ui-list): remove delimiter placeholder after last child
INSTUI-4639
1 parent 2c9931f commit c1032a0

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

packages/ui-list/src/InlineList/InlineListItem/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class InlineListItem extends Component<InlineListItemProps> {
5353
padding: 'none',
5454
spacing: 'none',
5555
delimiter: 'none',
56-
size: 'medium'
56+
size: 'medium',
57+
lastPlaceholder: false
5758
}
5859

5960
ref: Element | null = null
@@ -86,6 +87,7 @@ class InlineListItem extends Component<InlineListItemProps> {
8687
children,
8788
spacing,
8889
styles,
90+
lastPlaceholder,
8991
...rest
9092
} = this.props
9193

@@ -101,7 +103,9 @@ class InlineListItem extends Component<InlineListItemProps> {
101103
elementRef={this.handleRef}
102104
>
103105
{children}
104-
<span css={styles?.delimiter} aria-hidden="true" />
106+
{!lastPlaceholder && (
107+
<span css={styles?.delimiter} aria-hidden="true" />
108+
)}
105109
</View>
106110
)
107111
}

packages/ui-list/src/InlineList/InlineListItem/props.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ type InlineListItemOwnProps = {
7171
* provides a reference to the underlying html root element
7272
*/
7373
elementRef?: (element: Element | null) => void
74+
/**
75+
* Used internally to mark the last item as a placeholder
76+
*/
77+
lastPlaceholder?: boolean
7478
} & PropsWithChildren<unknown> // <unknown> is needed for React 17 compatibility
7579

7680
type PropKeys = keyof InlineListItemOwnProps
@@ -100,7 +104,8 @@ const propTypes: PropValidators<PropKeys> = {
100104
'x-large',
101105
'xx-large'
102106
]),
103-
elementRef: PropTypes.func
107+
elementRef: PropTypes.func,
108+
lastPlaceholder: PropTypes.bool
104109
}
105110

106111
const allowedProps: AllowedPropKeys = [

packages/ui-list/src/InlineList/__tests__/InlineList.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('<InlineList />', () => {
7575
)
7676
const delimiters = container.querySelectorAll('span[aria-hidden="true"]')
7777

78-
expect(delimiters.length).toEqual(4)
78+
expect(delimiters.length).toEqual(3)
7979
delimiters.forEach((delimiter) => {
8080
expect(delimiter.getAttribute('class')).toContain(
8181
'inlineListItem__delimiter'

packages/ui-list/src/InlineList/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ class InlineList extends Component<InlineListProps> {
6565
}
6666

6767
renderChildren() {
68-
return Children.map(this.props.children, (child) => {
69-
if (!child) return // ignore null, falsy children
68+
const childrenArray = Children.toArray(this.props.children)
69+
const lastIndex = childrenArray.length - 1
70+
71+
return childrenArray.map((child, index) => {
72+
if (!child) return null
73+
74+
const shouldRenderPlaceholder = index === lastIndex
7075

7176
return safeCloneElement(child as ReactElement, {
7277
delimiter: this.props.delimiter,
7378
size: this.props.size,
74-
spacing: this.props.itemSpacing
79+
spacing: this.props.itemSpacing,
80+
lastPlaceholder: shouldRenderPlaceholder
7581
})
7682
})
7783
}

0 commit comments

Comments
 (0)