ngx-ui-switch icon indicating copy to clipboard operation
ngx-ui-switch copied to clipboard

disabled attribute questions

Open AlexanderLea opened this issue 5 years ago • 11 comments

Hi,

We're using v8.0.1, and have had an issue today where we are setting

[disabled]="componentDisabled"

If we don't set componentDisabled in my component, and don't set a default value, the ngx-ui-switch appears to be defaulting to disabled=true.

The code inside ngx-ui-switch seems to be

@Input() set disabled(v: boolean) {
   this._disabled = v !== false;
 };

which suggests that anything other than explicit false will set disabled=true?

Is this the desired behaviour? - Am I missing something?

Alex

AlexanderLea avatar Jul 16 '19 09:07 AlexanderLea

interesting artifact from the original codebase. All of the explicit checks against false should be changed.

cmckni3 avatar Jul 16 '19 16:07 cmckni3

You accepting PRs?

AlexanderLea avatar Jul 17 '19 15:07 AlexanderLea

Yes

cmckni3 avatar Jul 17 '19 16:07 cmckni3

I believe reverse is broken as well based on #382.

PRs welcome

cmckni3 avatar Feb 25 '20 23:02 cmckni3

The code inside ngx-ui-switch seems to be

@Input() set disabled(v: boolean) { this._disabled = v !== false; }; which suggests that anything other than explicit false will set disabled=true?

Yes, that's correct but only when disabled is set at all.

      <!-- disabled=true (undefined value passed in) -->
      <ui-switch disabled></ui-switch>
      <!-- explicit disabled=true -->
      <ui-switch checked [disabled]="true"></ui-switch>

      <!-- disabled=false -->
      <ui-switch [disabled]="false"></ui-switch>

      <!-- componentDisabled = undefined => disabled=true -->
      <!-- componentDisabled = null => disabled=true -->
      <ui-switch [disabled]="componentDisabled"></ui-switch>

I am in favor of changing the check.

cmckni3 avatar Jul 30 '20 23:07 cmckni3

It's a bit confusing. Maybe use the value that is passed into disabled(v: boolean) as truthy/falsy?

What do you think @AlexanderLea?

cmckni3 avatar Jul 30 '20 23:07 cmckni3

Is there a reason that disabling the ui-switch does not add the disabled attribute to the underlying html button element? Not adding it means that if you use the (click)="someMethod()" event with the toggle, it will still fire when clicked, even when disabled, and css cursor: not-allowed.

Changing to use the (change)=someMethod()" does not have that same behavior, but I'm curious if there is a reason the button itself is not being disabled.

Chewieez avatar Jul 27 '23 16:07 Chewieez

Is there a reason that disabling the ui-switch does not add the disabled attribute to the underlying html button element? Not adding it means that if you use the (click)="someMethod()" event with the toggle, it will still fire when clicked, even when disabled, and css cursor: not-allowed.

Changing to use the (change)=someMethod()" does not have that same behavior, but I'm curious if there is a reason the button itself is not being disabled.

Probably just overlooked when initially implemented. Never looked into adding it.

cmckni3 avatar Jul 30 '23 19:07 cmckni3

Probably just overlooked when initially implemented. Never looked into adding it.

Gotcha. I will look into creating a PR for adding it.

Chewieez avatar Aug 01 '23 15:08 Chewieez

Probably just overlooked when initially implemented. Never looked into adding it.

Gotcha. I will look into creating a PR for adding it.

Sounds good. Thanks!

cmckni3 avatar Aug 01 '23 15:08 cmckni3

Found the issue here. Angular can pass the input as string in certain cases. working a fix

Related to #382

cmckni3 avatar Nov 01 '23 03:11 cmckni3