Skip to content

Commit 9f28507

Browse files
committed
chore(Placeholder): use React.forwardRef() (#4236)
1 parent 640c57d commit 9f28507

File tree

11 files changed

+27
-16
lines changed

11 files changed

+27
-16
lines changed

src/elements/Placeholder/Placeholder.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import PlaceholderParagraph from './PlaceholderParagraph'
1717
/**
1818
* A placeholder is used to reserve space for content that soon will appear in a layout.
1919
*/
20-
function Placeholder(props) {
20+
const Placeholder = React.forwardRef(function PlaceholderInner(props, ref) {
2121
const { children, className, content, fluid, inverted } = props
2222
const classes = cx(
2323
'ui',
@@ -30,12 +30,13 @@ function Placeholder(props) {
3030
const ElementType = getElementType(Placeholder, props)
3131

3232
return (
33-
<ElementType {...rest} className={classes}>
33+
<ElementType {...rest} className={classes} ref={ref}>
3434
{childrenUtils.isNil(children) ? content : children}
3535
</ElementType>
3636
)
37-
}
37+
})
3838

39+
Placeholder.displayName = 'Placeholder'
3940
Placeholder.propTypes = {
4041
/** An element type to render as (string or function). */
4142
as: PropTypes.elementType,

src/elements/Placeholder/PlaceholderHeader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ import {
1313
/**
1414
* A placeholder can contain a header.
1515
*/
16-
function PlaceholderHeader(props) {
16+
const PlaceholderHeader = React.forwardRef(function PlaceholderHeaderInner(props, ref) {
1717
const { children, className, content, image } = props
1818
const classes = cx(useKeyOnly(image, 'image'), 'header', className)
1919
const rest = getUnhandledProps(PlaceholderHeader, props)
2020
const ElementType = getElementType(PlaceholderHeader, props)
2121

2222
return (
23-
<ElementType {...rest} className={classes}>
23+
<ElementType {...rest} className={classes} ref={ref}>
2424
{childrenUtils.isNil(children) ? content : children}
2525
</ElementType>
2626
)
27-
}
27+
})
2828

29+
PlaceholderHeader.displayName = 'PlaceholderHeader'
2930
PlaceholderHeader.propTypes = {
3031
/** An element type to render as (string or function). */
3132
as: PropTypes.elementType,

src/elements/Placeholder/PlaceholderImage.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { customPropTypes, getElementType, getUnhandledProps, useKeyOnly } from '
77
/**
88
* A placeholder can contain an image.
99
*/
10-
function PlaceholderImage(props) {
10+
const PlaceholderImage = React.forwardRef(function PlaceholderImageInner(props, ref) {
1111
const { className, square, rectangular } = props
1212
const classes = cx(
1313
useKeyOnly(square, 'square'),
@@ -18,9 +18,10 @@ function PlaceholderImage(props) {
1818
const rest = getUnhandledProps(PlaceholderImage, props)
1919
const ElementType = getElementType(PlaceholderImage, props)
2020

21-
return <ElementType {...rest} className={classes} />
22-
}
21+
return <ElementType {...rest} className={classes} ref={ref} />
22+
})
2323

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

src/elements/Placeholder/PlaceholderLine.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import { getElementType, getUnhandledProps } from '../../lib'
77
/**
88
* A placeholder can contain have lines of text.
99
*/
10-
function PlaceholderLine(props) {
10+
const PlaceholderLine = React.forwardRef(function PlaceholderLineInner(props, ref) {
1111
const { className, length } = props
1212
const classes = cx('line', length, className)
1313
const rest = getUnhandledProps(PlaceholderLine, props)
1414
const ElementType = getElementType(PlaceholderLine, props)
1515

16-
return <ElementType {...rest} className={classes} />
17-
}
16+
return <ElementType {...rest} className={classes} ref={ref} />
17+
})
1818

19+
PlaceholderLine.displayName = 'PlaceholderLine'
1920
PlaceholderLine.propTypes = {
2021
/** An element type to render as (string or function). */
2122
as: PropTypes.elementType,

src/elements/Placeholder/PlaceholderParagraph.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 can contain a paragraph.
99
*/
10-
function PlaceholderParagraph(props) {
10+
const PlaceholderParagraph = React.forwardRef(function PlaceholderParagraphInner(props, ref) {
1111
const { children, className, content } = props
1212
const classes = cx('paragraph', className)
1313
const rest = getUnhandledProps(PlaceholderParagraph, props)
1414
const ElementType = getElementType(PlaceholderParagraph, 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+
PlaceholderParagraph.displayName = 'PlaceholderParagraph'
2324
PlaceholderParagraph.propTypes = {
2425
/** An element type to render as (string or function). */
2526
as: PropTypes.elementType,

test/specs/commonTests/isConformant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function isConformant(Component, options = {}) {
7373
const isTopLevelAPIProp = _.has(semanticUIReact, constructorName)
7474

7575
// find the apiPath in the semanticUIReact object
76-
const foundAsSubcomponent = _.isFunction(_.get(semanticUIReact, info.apiPath))
76+
const foundAsSubcomponent = ReactIs.isValidElementType(_.get(semanticUIReact, info.apiPath))
7777

7878
// require all components to be exported at the top level
7979
it('is exported at the top level', () => {

test/specs/elements/Placeholder/Placeholder-test.js

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

88
describe('Placeholder', () => {
99
common.isConformant(Placeholder)
10+
common.forwardsRef(Placeholder)
1011
common.hasSubcomponents(Placeholder, [
1112
PlaceholderHeader,
1213
PlaceholderImage,

test/specs/elements/Placeholder/PlaceholderHeader-test.js

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

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

89
common.propKeyOnlyToClassName(PlaceholderHeader, 'image')

test/specs/elements/Placeholder/PlaceholderImage-test.js

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

44
describe('PlaceholderImage', () => {
55
common.isConformant(PlaceholderImage)
6+
common.forwardsRef(PlaceholderImage)
67

78
common.propKeyOnlyToClassName(PlaceholderImage, 'square')
89
common.propKeyOnlyToClassName(PlaceholderImage, 'rectangular')

test/specs/elements/Placeholder/PlaceholderLine-test.js

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

44
describe('PlaceholderLine', () => {
55
common.isConformant(PlaceholderLine)
6+
common.forwardsRef(PlaceholderLine)
7+
68
common.propValueOnlyToClassName(PlaceholderLine, 'length', [
79
'full',
810
'very long',

test/specs/elements/Placeholder/PlaceholderParagraph-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('PlaceholderParagraph', () => {
55
common.isConformant(PlaceholderParagraph)
6+
common.forwardsRef(PlaceholderParagraph)
67
common.rendersChildren(PlaceholderParagraph)
78
})

0 commit comments

Comments
 (0)