nz-toggle
nz-toggle copied to clipboard
Unexpected state after click
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?
Hi,
Yes this is the expected behaviour. You also have the option of dragging it to the direction you want.
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();
}
}
}