Skip to content
Merged
Changes from all commits
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
16 changes: 11 additions & 5 deletions src/components/Hoverable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,21 @@ const Hoverable = React.forwardRef(({disabled, onHoverIn, onHoverOut, onMouseEnt
[child.props],
);

// We need to access the ref of a children from both parent and current component
// So we pass it to current ref and assign it once again to the child ref prop
const hijackRef = (el) => {
ref.current = el;
assignRef(child.ref, el);
};

if (!DeviceCapabilities.hasHoverSupport()) {
return child;
return React.cloneElement(child, {
ref: hijackRef,
});
}

return React.cloneElement(child, {
ref: (el) => {
ref.current = el;
assignRef(child.ref, el);
},
ref: hijackRef,
onMouseEnter: enableHoveredOnMouseEnter,
onMouseLeave: disableHoveredOnMouseLeave,
onBlur: disableHoveredOnBlur,
Expand Down