import ReactDom from 'react-dom';

export class FocusHelper {
    $el = null;
    setEl = el => (this.$el = el);
    focus = () => {
        let $el: any = this.$el;
        if ($el) {
            if ($el.focus) {
                $el.focus();
            } else {
                $el = ReactDom.findDOMNode($el);
                if ($el && $el.focus) {
                    $el.focus();
                }
            }
        }
    };
    setElAndFocus = el => {
        this.setEl(el);
        this.focus();
    };
}
