Skip to content

Commit 89e392f

Browse files
committed
chore(Segment): use React.forwardRef() (#4238)
1 parent 80e4484 commit 89e392f

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

src/elements/Segment/Segment.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SegmentInline from './SegmentInline'
2020
/**
2121
* A segment is used to create a grouping of related content.
2222
*/
23-
function Segment(props) {
23+
const Segment = React.forwardRef(function SegmentInner(props, ref) {
2424
const {
2525
attached,
2626
basic,
@@ -76,15 +76,16 @@ function Segment(props) {
7676
const ElementType = getElementType(Segment, props)
7777

7878
return (
79-
<ElementType {...rest} className={classes}>
79+
<ElementType {...rest} className={classes} ref={ref}>
8080
{childrenUtils.isNil(children) ? content : children}
8181
</ElementType>
8282
)
83-
}
83+
})
8484

8585
Segment.Group = SegmentGroup
8686
Segment.Inline = SegmentInline
8787

88+
Segment.displayName = 'Segment'
8889
Segment.propTypes = {
8990
/** An element type to render as (string or function). */
9091
as: PropTypes.elementType,

src/elements/Segment/SegmentGroup.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
/**
1616
* A group of segments can be formatted to appear together.
1717
*/
18-
function SegmentGroup(props) {
18+
const SegmentGroup = React.forwardRef(function SegmentGroupInner(props, ref) {
1919
const { children, className, compact, content, horizontal, piled, raised, size, stacked } = props
2020

2121
const classes = cx(
@@ -33,12 +33,13 @@ function SegmentGroup(props) {
3333
const ElementType = getElementType(SegmentGroup, props)
3434

3535
return (
36-
<ElementType {...rest} className={classes}>
36+
<ElementType {...rest} className={classes} ref={ref}>
3737
{childrenUtils.isNil(children) ? content : children}
3838
</ElementType>
3939
)
40-
}
40+
})
4141

42+
SegmentGroup.displayName = 'SegmentGroup'
4243
SegmentGroup.propTypes = {
4344
/** An element type to render as (string or function). */
4445
as: PropTypes.elementType,

src/elements/Segment/SegmentInline.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ import { childrenUtils, customPropTypes, getElementType, getUnhandledProps } fro
77
/**
88
* A placeholder segment can be inline.
99
*/
10-
function SegmentInline(props) {
10+
const SegmentInline = React.forwardRef(function SegmentInlineInner(props, ref) {
1111
const { children, className, content } = props
1212
const classes = cx('inline', className)
1313
const rest = getUnhandledProps(SegmentInline, props)
1414
const ElementType = getElementType(SegmentInline, props)
1515

1616
return (
17-
<ElementType {...rest} className={classes}>
17+
<ElementType {...rest} className={classes} ref={ref}>
1818
{childrenUtils.isNil(children) ? content : children}
1919
</ElementType>
2020
)
21-
}
21+
})
2222

23+
SegmentInline.displayName = 'SegmentInline'
2324
SegmentInline.propTypes = {
2425
/** An element type to render as (string or function). */
2526
as: PropTypes.elementType,

test/specs/elements/Segment/Segment-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as common from 'test/specs/commonTests'
88

99
describe('Segment', () => {
1010
common.isConformant(Segment)
11+
common.forwardsRef(Segment)
1112
common.hasSubcomponents(Segment, [SegmentGroup, SegmentInline])
1213
common.hasUIClassName(Segment)
1314
common.rendersChildren(Segment)

test/specs/elements/Segment/SegmentGroup-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as common from 'test/specs/commonTests'
66

77
describe('SegmentGroup', () => {
88
common.isConformant(SegmentGroup)
9+
common.forwardsRef(SegmentGroup)
910
common.hasUIClassName(SegmentGroup)
1011
common.rendersChildren(SegmentGroup)
1112

test/specs/elements/Segment/SegmentInline-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import * as common from 'test/specs/commonTests'
33

44
describe('SegmentInline', () => {
55
common.isConformant(SegmentInline)
6+
common.forwardsRef(SegmentInline)
67
common.rendersChildren(SegmentInline)
78
})

0 commit comments

Comments
 (0)