tannerlinsley / nz-toggle

Dual and triple-state toggles for AngularJS
http://codepen.io/anon/pen/yNjyME
40 stars 30 forks source link

Unexpected state after click #25

Open hartmannj opened 8 years ago

hartmannj commented 8 years ago

The interaction seems to go against the mental model of a switch. If I click on the right side of a switch, it should switch to the right side and the other way round. Right now it has a predefined order no matter which side I click. Is this the expected behaviour?

ckr commented 8 years ago

Hi,

Yes this is the expected behaviour. You also have the option of dragging it to the direction you want.

StylishFlash commented 7 years ago

I had the same problem. I solved it by changing onClick to:

            function onClick(e) {

                if (movement < 1) {

                    if (vm.state === 'null') {

                        const element = angular.element(this);
                        const width = element.innerWidth(); //use .outerWidth() if you want borders
                        const offset = element.offset(); 
                        const x = e.pageX - offset.left;
                        const middle = width / 2;

                        if (x < middle) {

                            toggle('false');

                        } else {

                            toggle('true');

                        } 

                    } else {

                        toggle();

                    }

                }

            }