Ng-zorro-antd: [RFC] Make all boolean attribute `false` by default

Created on 20 Oct 2017  ·  14Comments  ·  Source: NG-ZORRO/ng-zorro-antd

I'm submitting a...


[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Support request => Please do not submit support request here

Content

It's much easier and instinctive to specify an attribute for applying it (rather than strip it).

Consider:

<!-- truthy -->
<nz-cascader></nz-cascader>
<!-- falsy -->
<nz-cascader [nzShowInput]="false" [nzShowArrow]="false"></nz-cascader>

Versus:

<!-- truthy -->
<nz-cascader></nz-cascader>
<!-- falsy -->
<nz-cascader [nzNoInput]="true" [nzNoArrow]="true"></nz-cascader>

The latter can then be simplified to:

<!-- truthy -->
<nz-cascader></nz-cascader>
<!-- falsy -->
<nz-cascader nzNoInput nzNoArrow></nz-cascader>

This way we could keep consistency with HTML boolean attributes, and the value part could always be omitted while remain effective.

It can make non-binding usage much simpler. For binding usage, just need to add or remove an ! operator.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z

ng-zorro-antd version: X.Y.Z

Browser:
- [ ] Chrome (desktop) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] IE version XX

For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Most helpful comment

@ghost Haven't you used disabled on <input>? This is the suggested way in most React libs (including antd) and Angular libs (including this one), just trying to make it applicable for more components.

All 14 comments

这种用法会混淆 Directive 和 Input,感觉用起来怪怪的。

@ghost Haven't you used disabled on <input>? This is the suggested way in most React libs (including antd) and Angular libs (including this one), just trying to make it applicable for more components.

@trotyl what if user want to dynamic change the attribute

@vthinkxie Will keep the same behavior as input[disabled], namely:

<input disabled>
<nz-cascader nzNoInput nzNoArrow></nz-cascader>

Are used for static mockup, while:

<input [disabled]="condition">
<nz-cascader [nzNoInput]="condition" [nzNoArrow]="condition"></nz-cascader>

Applies to dynamic binding.

The only change is that if user writes condition before, they need to use !condition now, and vice versa.

Currently if some user want to use only static markup, they still need to manually binds to a false value, like:

<nz-cascader [nzShowInput]="false" [nzShowArrow]="false"></nz-cascader>

That's too much boilerplate.

@trotyl
Some components are designed as your description already, but change all boolean attribute false by default will bring some break changes, would you please figure out these changes?

@vthinkxie I'll have a thorough check.

Boolean inputs with true by default (so must have a value):

  • NzCalendarComponent#nzClearTime
  • NzCalendarComponent#nzFullScreen
  • NzCalendarComponent#nzShowHeader
  • NzCardComponent#nzBordered
  • NzCarouselComponent#nzDots
  • NzCascaderComponent#nzShowInput
  • NzCascaderComponent#nzAllowClear
  • NzCascaderComponent#nzShowArrow
  • NzCascaderComponent#nzEnableCache
  • NzConfirmComponent#nzMaskClosable
  • NzDatePickerComponent#nzAllowClear
  • NzDropDownComponent#nzClickHide
  • NzDropDownButtonComponent#nzClickHide
  • NzMenuComponent#nzClickActive
  • NzModalComponent#nzClosable
  • NzModalComponent#nzMaskClosable
  • NzProgressComponent#nzShowInfo
  • NzSelectComponent#nzFilter
  • NzSliderComponent#nzIncluded
  • NzSpinComponent#nzSpinning
  • NzTabsNavComponent#nzAnimated
  • NzTabsNavComponent#nzShowPagination
  • NzTabSetComponent#nzAnimated
  • NzTabSetComponent#nzShowPagination

Boolean inputs with false by default (but not support no value):

  • NzAlertComponent#nzBanner
  • NzAlertComponent#nzCloseable
  • NzAlertComponent#nzShowIcon
  • NzBadgeComponent#nzDot
  • NzButtonComponent#nzGhost
  • NzButtonComponent#nzLoading
  • NzCalendarComponent#nzDatePicker
  • NzCardComponent#nzLoading
  • NzCardComponent#nzNoHovering
  • NzCarouselComponent#nzAutoPlay
  • NzCarouselComponent#nzVertical
  • NzCascaderComponent#nzDisabled
  • NzCascaderComponent#nzShowSearch
  • NzCascaderComponent#nzChangeOnSelect
  • NzCheckboxGroupComponent#nzDisabled
  • NzCheckboxGroupComponent#nzIndeterminate
  • NzCollapseComponent#nzDisabled
  • NzCollapseComponent#nzActive
  • NzConfirmComponent#nzVisible
  • NzConfirmComponent#nzConfirmLoading
  • NzDropDownButtonComponent#nzDisable
  • NzDropDownButtonComponent#nzVisible
  • NzDropDownComponent#nzVisible
  • NzModalComponent#nzVisible
  • NzModalComponent#nzConfirmLoading
  • NzMenuItemComponent#nzDisable
  • NzMenuItemComponent#nzSelected
  • NzMenuComponent#nzInlineCollapsed
  • NzOptionComponent#nzDisabled
  • NzPopconfirmComponent#nzCondition
  • NzRadioButtonComponent#nzDisabled
  • NzRadioComponent#nzChecked
  • NzRadioComponent#nzDisabled
  • NzRateComponent#nzDisabled
  • NzRowExpandIconComponent#nzExpand
  • NzRowExpandIconComponent#nzShowExpand
  • NzSelectComponent#nzShowSearch
  • NzSelectComponent#nzDisabled
  • NzSelectComponent#nzOpen
  • NzSiderComponent#nzCollapsed
  • NzSliderMarksComponent#nzVertical
  • NzSliderMarksComponent#nzIncluded
  • NzSliderStepComponent#nzVertical
  • NzSliderStepComponent#nzIncluded
  • NzSliderTrackComponent#nzVertical
  • NzSliderTrackComponent#nzIncluded
  • NzSliderComponent#nzDisabled
  • NzSliderComponent#nzDots
  • NzStepsComponent#nzProgressDot
  • NzSubMenuComponent#nzOpen
  • NzSwitchComponent#nzDisabled
  • NzTableComponent#nzBordered
  • NzTableComponent#nzCustomNoResult
  • NzTableComponent#nzLoading
  • NzTableComponent#nzShowSizeChanger
  • NzTableComponent#nzShowQuickJumper
  • NzTableComponent#nzShowTotal
  • NzTableComponent#nzShowFooter
  • NzTableComponent#nzShowTitle
  • NzTdDirective#nzCheckbox
  • NzTdDirective#nzExpand
  • NzThDirective#nzCheckbox
  • NzThDirective#nzExpand
  • NzTabLabelDirective#disabled
  • NzTabsInkBarDirective#nzAnimated
  • NzTabsNavComponent#nzHideBar
  • NzTabSetComponent#nzHide
  • NzCheckableTagComponent#nzChecked
  • NzCheckableTagComponent#nzClosable
  • NzTagComponent#nzClosable
  • NzTimePickerInnerComponent#nzDisabled
  • NzTimePickerComponent#nzDisabled

Boolean inputs already supports no value truthy:

  • NzBadgeComponent#nzShowZero
  • NzFormControlComponent#nzHasFeedback
  • NzSiderComponent#nzCollapsible
  • NzPaginationComponent#nzShowSizeChanger
  • NzPaginationComponent#nzShowQuickJumper
  • NzPaginationComponent#nzShowTotal
  • NzPaginationComponent#nzSimple
  • NzRateComponent#nzAllowHalf
  • NzSelectComponent#nzAllowClear
  • NzSelectComponent#nzKeepUnListOptions
  • NzSliderComponent#nzVertical
  • NzTableComponent#nzIsPagination
  • NzTableComponent#nzIsPageIndexReset
  • NzTimePickerInnerComponent#nzHideDisabledOptions

@trotyl
it seems that many break changes will happened if make all boolean attribute false by default
what about make all boolean inputs with false by default support no value truthy first
and the bring the break change in the further version such as 0.6.x or 0.7.x

Actually we don't need to remove the old ones (in near future), it's easy to provide different getter/setter with the same internal.

@trotyl
that is ok, we can give a warning or something before we remove the old ones.

Waiting for https://github.com/angular/angular/issues/19929.

Update: since no quick response there, will use NgModel#disabled implementation for reference.

import { toBoolean } from '../util/convert';

Maybe much better in this way:

import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';

@cipchk Agree with that.

done with @InputBoolean in the latest version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ismezy picture ismezy  ·  3Comments

lsbbd picture lsbbd  ·  3Comments

JCqiu picture JCqiu  ·  3Comments

bambooj picture bambooj  ·  4Comments

cipchk picture cipchk  ·  4Comments