Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/buttons/src/views/icon-button/ChevronButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ChevronButton.propTypes = {
hovered: PropTypes.bool,
active: PropTypes.bool,
/** Callback for reference of the native button element */
buttonRef: PropTypes.func,
buttonRef: PropTypes.any,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is any really the appropriate choice here? It should only be an object or a function, right?

In the other hand, if you actually want to enforce the type of an actual ref, for example a prop that is forwarded to another component's ref, you have to allow both on object shaped by React.createRef() (The preferred way to create ref in React components, see type in react code here) and function types.

Object shape: PropTypes.shape({ current: PropTypes.instanceOf(Element) }) is for refs created using React.createRef()
PropTypes.func is for callback refs as used in the above question
Which gives the following PropType definition:

forwardRef: PropTypes.oneOfType([
  PropTypes.func, 
  PropTypes.shape({ current: PropTypes.instanceOf(Element) })
])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have avoided the shape prop-type in other packages which is why I went with any here.

We ended up removing them as they actually don't do anything in the v6+ world.

/** Rotates icon 180 degrees */
rotated: PropTypes.bool
};
Expand Down
2 changes: 1 addition & 1 deletion packages/buttons/src/views/icon-button/IconButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ IconButton.propTypes = {
hovered: PropTypes.bool,
active: PropTypes.bool,
/** Callback for reference of the native button element */
buttonRef: PropTypes.func
buttonRef: PropTypes.any
};

IconButton.defaultProps = {
Expand Down