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

Incomplete typing for ngTooltip directive #3845

Closed
aha-tech opened this issue Sep 5, 2020 · 0 comments
Closed

Incomplete typing for ngTooltip directive #3845

aha-tech opened this issue Sep 5, 2020 · 0 comments

Comments

@aha-tech
Copy link

aha-tech commented Sep 5, 2020

Bug description:

The input for the ngTooltip directive is defined as

  /**
   * The string content or a `TemplateRef` for the content to be displayed in the tooltip.
   *
   * If the content if falsy, the tooltip won't open.
   */
  @Input()
  set ngbTooltip(value: string | TemplateRef<any>) {

As the comment notes, the input can be falsy, however, the only falsy value allowed by the types is the empty string. It would be nice if the typing also allod for null and undefined. Running angular/typescript in strict mode makes it rather inconvenient to bind ngTooltip to a nullable property at the moment.

Link to minimally-working StackBlitz that reproduces the issue:

https://stackblitz.com/edit/angular-jhnsp4-yzls3r?file=src/app/tooltip-basic.html

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 10.1

ng-bootstrap: 7.0.0

Bootstrap: 4.5.2

jnizet added a commit to jnizet/ng-bootstrap that referenced this issue Sep 6, 2020
The documentation says that falsy values are accepted, but in strict mode, only the empty string could actually be passed.

fix ng-bootstrap#3845
jnizet added a commit to jnizet/ng-bootstrap that referenced this issue Sep 6, 2020
This makes it consistent with the behavior of tooltip. It also makes more sense since the title is an optional input, and its default value is thus undefined (which, in strict mode, is neither a string nor a TemplateRef).
Note that a test checked that no title was displayed when the title was empty, but it actually checked that no title was displayed if the title was undefined. And it *did* display an empty title if the title was an empty string.
Now, the title is displayed only is it is truthy.

refs ng-bootstrap#3845
maxokorokov pushed a commit to jnizet/ng-bootstrap that referenced this issue Nov 3, 2020
The documentation says that falsy values are accepted, but in strict mode, only the empty string could actually be passed.

fix ng-bootstrap#3845
maxokorokov pushed a commit to jnizet/ng-bootstrap that referenced this issue Nov 3, 2020
This makes it consistent with the behavior of tooltip. It also makes more sense since the title is an optional input, and its default value is thus undefined (which, in strict mode, is neither a string nor a TemplateRef).
Note that a test checked that no title was displayed when the title was empty, but it actually checked that no title was displayed if the title was undefined. And it *did* display an empty title if the title was an empty string.
Now, the title is displayed only is it is truthy.

refs ng-bootstrap#3845
maxokorokov pushed a commit that referenced this issue Nov 3, 2020
This makes it consistent with the behavior of tooltip. It also makes more sense since the title is an optional input, and its default value is thus undefined (which, in strict mode, is neither a string nor a TemplateRef).
Note that a test checked that no title was displayed when the title was empty, but it actually checked that no title was displayed if the title was undefined. And it *did* display an empty title if the title was an empty string.
Now, the title is displayed only is it is truthy.

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

No branches or pull requests

2 participants