H
H
hadaev_ivan2015-06-03 13:35:00
JavaScript
hadaev_ivan, 2015-06-03 13:35:00

How do you solve the onBlur/onFocus problem?

You hang onBlur / onFocus on the element and when you click on the element (child) again, the focus and blur work once again breaking my drop-down datepicker It's clear that there are other ways to solve the problem, but with blur / focus it would seem more logical

render: function () {
        var component = this;
        var props = component.props;
        var state = component.state;

        return (
            <div>
                <label onFocus={component.onOpenDateRangePicker} onBlur={component.onCloseDateRangePicker}>
                    <input
                        className="date-range-picker-input"
                        value={component.state.value}/>

                    <div className={classNames('date-picker-wrapper', {hidden: !state.isOpened})}>
                        <DateRangePicker />
                    </div>
                </label>
            </div>
        );
    },
    onOpenDateRangePicker: function (event) {
        var component = this;
        debugger;

        component.setState({
            isOpened: true
        });
        console.log('focus');
    },
    onCloseDateRangePicker: function (event) {
        var component = this;
        debugger;
        component.setState({
            isOpened: false
        });
        console.log('blur');
    }

How do you solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
@
@ngreduce, 2015-06-11
_

Try putting onFocus/onBlur on input.
I just checked in my application and I do not observe such an effect.

A
Artem Kustikov, 2015-06-11
@art1z

Check the real target of the event, something like this:
if(event.target.localName != 'input')
return;
https://jsfiddle.net/wxm0087c/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question