File tree Expand file tree Collapse file tree 4 files changed +22
-7
lines changed
packages/ui-list/src/InlineList Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
7680type 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
106111const allowedProps : AllowedPropKeys = [
Original file line number Diff line number Diff 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'
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments