Focusable component declared as forwardable ref

This commit is contained in:
NikolaBorislavovHristov 2019-01-22 10:09:39 +02:00
parent 271d113ef1
commit 127949d126

View file

@ -1,12 +1,12 @@
import React from 'react';
import FocusableContext from './FocusableContext';
const Focusable = ({ children }) => {
const Focusable = React.forwardRef(({ children, ...props }, ref) => {
return (
<FocusableContext.Consumer>
{focusable => React.cloneElement(React.Children.only(children), { tabIndex: focusable ? 0 : -1 })}
{focusable => React.cloneElement(React.Children.only(children), { ...props, ref, tabIndex: focusable ? 0 : -1 })}
</FocusableContext.Consumer>
);
};
});
export default Focusable;