Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[touch] button: Does not emit click on first try #2033

Open
tadatuta opened this issue Apr 16, 2017 · 8 comments
Open

[touch] button: Does not emit click on first try #2033

tadatuta opened this issue Apr 16, 2017 · 8 comments
Labels

Comments

@tadatuta
Copy link
Member

No description provided.

@rtemision
Copy link

rtemision commented Apr 18, 2017

If you change the type of event from pointerclick to click in method _onPointerRelease: https://github.com/bem/bem-components/blob/v5.0.0/common.blocks/button/button.js#L117 , then it works. So, I guess problem in https://github.com/bem/bem-core/blob/v4/common.blocks/jquery/__event/_type/jquery__event_type_pointerclick.js

@belozer
Copy link
Member

belozer commented May 23, 2017

https://github.com/bem/bem-components/blob/v3/common.blocks/button/button.js#L106

У меня почему-то подозрения на это место. Подписка делается только тогда, когда событие всплыло уже на самый верх документа.

У нас на проекте профиксил локально переопределив 3 метода. Только не знаю как правильно должна быть подписка на pointerclick (bindTo или bindToDoc) оно и так и так работает нормально, но не зря ведь подписка на клик была после всплытия...

    _onPointerPress : function() {
        this.bindTo('mousedown', this._onMouseDown);
        if(!this.hasMod('disabled')) {
            this._isPointerPressInProgress = true;
            this
                .bindToDoc('pointerrelease', this._onPointerRelease)
                .bindToDoc('pointerclick', this._onPointerClick) 
                .setMod('pressed');
        }
    },

    _onPointerRelease : function(e) {
        this._isPointerPressInProgress = false;
        this.unbindFromDoc('pointerrelease', this._onPointerRelease);

        if(e.originalEvent.type === 'pointerup' && dom.contains(this.elem('control'), $(e.target))) {
            this._focusedByPointer = true;
            this._focus();
            this._focusedByPointer = false;
        } else {
            this._blur();
        }

        this.delMod('pressed');
    },

    _onPointerClick : function() {
        this
            .unbindFromDoc('pointerclick', this._onPointerClick)
            ._updateChecked()
            .emit('click');
    },

Если решение годное, могу прислать PR.

//cc @tadatuta

@rtemision
Copy link

Я локально решил, выпилив из jquery__event_type_pointerclick.js условие для ios.

@belozer
Copy link
Member

belozer commented May 23, 2017

@rteamx проблема не в pointerclick, а в моменте его подписки.

@rtemision
Copy link

@belozer ну да, согласен.

@belozer
Copy link
Member

belozer commented May 29, 2017

Тесты правда упали с таким решением...

Но если исключить вообще историю про pointerclick, то тесты зелёные и отрабатывает правильно.

    _onPointerRelease : function(e) {
        this._isPointerPressInProgress = false;
        this.unbindFromDoc('pointerrelease', this._onPointerRelease);

        if(e.originalEvent.type === 'pointerup' && dom.contains(this.elem('control'), $(e.target))) {
            this._focusedByPointer = true;
            this._focus();
            this._focusedByPointer = false;
            this
                ._updateChecked()
                .emit('click');
        } else {
            this._blur();
        }

        this.delMod('pressed');
    },

@veged
Copy link
Member

veged commented Jan 10, 2018

+@veged +@awinogradov

@ijakparov
Copy link

Доопределение button.js с заменой pointerclick на click

modules.define(
    'button',
    ['i-bem-dom', 'jquery', 'dom'],
    function(provide, bemDom, $, dom, Button) {

        provide(bemDom.declBlock(Button,{

            _onPointerRelease : function(e) {
                this._isPointerPressInProgress = false;
                this._domEvents(bemDom.doc).un('pointerrelease', this._onPointerRelease);

                if(e.originalEvent.type === 'pointerup' && dom.contains(this.findMixedElem('control').domElem, $(e.target))) {
                    this._focusedByPointer = true;
                    this._focus();
                    this._focusedByPointer = false;
                    this._domEvents().once('click', this._onPointerClick);
                } else {
                    this._blur();
                }

                this.delMod('pressed');
            },

            _onPointerClick : function() {
                this.__base();
            },


        }));

    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants