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

fix(kit): icon in date-related components occupies space when hidden #2966

Merged
merged 1 commit into from
Nov 9, 2022

Conversation

theorlovsky
Copy link
Contributor

@theorlovsky theorlovsky commented Oct 26, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows Conventional Commits
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Refactoring
  • Code style update
  • Build or CI related changes
  • Documentation content changes

What is the current behavior?

Closes #2960

What is the new behavior?

Icon is completely hidden when removed via DI

Does this PR introduce a breaking change?

  • Yes
  • No

@@ -11,7 +11,7 @@
automation-id="tui-input-date-range__textfield"
tuiValueAccessor
class="t-textfield"
[tuiTextfieldIcon]="computedMobile ? mobileIconContent : iconContent"
[tuiTextfieldIcon]="hasCalendarIcon ? (computedMobile ? mobileIconContent : iconContent) : null"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about implementing the pipe?

[tuiTextfieldIcon]="calendarIcon | tuiPresent ? (computedMobile ? mobileIconContent : iconContent) : null"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a good idea

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There no need for a pipe like that, it only complicates things, besides empty string is also lack of icon, not just null. There's also no need for nesting a ternary operator, you can write it like that:

[tuiTextfieldIcon]="computedMobile ? mobileIconContent : (calendarIcon && iconContent)"

If calendarIcon is falsy (empty string or null) it is passed to tuiTextfieldIcon, disabling the icon, otherwise iconContent is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but what about mobileIconContent? it should not be present as well

Copy link
Contributor Author

@theorlovsky theorlovsky Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides, an empty string still renders tui-svg, it just has nothing to show. while null doesn't render anything

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the pipe, it would be a useful addition to the cdk but I don't think we really need it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waterplea do you want me to move the pipe to a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for this one

[tuiTextfieldIcon]="calendarIcon && iconContent"

I still don't think that this is a right solution. if calendarIcon is an empty string, then the expression '' && iconContent becomes just '' and you'll get an empty tui-svg rendered, as shown on the screenshot above. so the bug with an empty space next to a cleaner won't be fixed (which is a purpose of this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I've just figured out that because of this very reason we don't need the pipe here 🙂
because it filters out only nil values, but we need an empty string to be removed as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you handle such cases in Taiga?

onIconClick(): void {
    if (!this.computedMobile) { // <-- this.isMobile && !!this.mobileCalendar
        return;
    }

    this.dialogService
        .open<TuiDay>(new PolymorpheusComponent(this.mobileCalendar, this.injector), {
        // 'Type<object> | null' is not assignable... ^^^^^^^^^^^^
}

I could add ! to mobileCalendar, but it's not type safe, and the linter is also not happy with this solution

just check it again?

if (!this.computedMobile || !this.mobileCalendar) {
    return;
}

@lumberjack-bot
Copy link

lumberjack-bot bot commented Oct 28, 2022

Pull request was closed ✔️

All saved screenshots (for current PR) were deleted 🗑️

@theorlovsky
Copy link
Contributor Author

I forgot to add docs for tuiIsPresent pipe, will do it now

@bundlemon
Copy link

bundlemon bot commented Oct 28, 2022

BundleMon

Files updated (1)
Status Path Size Limits
demo/browser/main.(hash).js
323.08KB (-178B -0.05%) +10%
Unchanged files (4)
Status Path Size Limits
demo/browser/vendor.(hash).js
205.38KB +10%
demo/browser/runtime.(hash).js
34.05KB +10%
demo/browser/polyfills.(hash).js
19.92KB +10%
demo/browser/scripts.(hash).js
14.92KB +10%

Total files change -178B -0.03%

Groups updated (1)
Status Path Size Limits
demo/browser/*..js
2.17MB (-178B -0.01%) -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@codecov
Copy link

codecov bot commented Oct 28, 2022

Codecov Report

Base: 61.79% // Head: 61.89% // Increases project coverage by +0.10% 🎉

Coverage data is based on head (c6627c0) compared to base (3c219c1).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2966      +/-   ##
==========================================
+ Coverage   61.79%   61.89%   +0.10%     
==========================================
  Files        1473     1483      +10     
  Lines       17403    17559     +156     
  Branches     2364     2395      +31     
==========================================
+ Hits        10754    10868     +114     
- Misses       6210     6253      +43     
+ Partials      439      438       -1     
Flag Coverage Δ
addon-charts 72.48% <ø> (ø)
addon-doc 48.46% <ø> (ø)
addon-editor 51.59% <ø> (-1.62%) ⬇️
addon-mobile 62.31% <ø> (+0.62%) ⬆️
addon-table 64.06% <ø> (ø)
addon-tablebars 98.07% <ø> (ø)
cdk 40.26% <ø> (-0.02%) ⬇️
core 76.79% <ø> (+0.56%) ⬆️
kit 74.14% <0.00%> (+0.51%) ⬆️
summary 61.89% <0.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...nts/input-date-range/input-date-range.component.ts 75.00% <0.00%> (+0.68%) ⬆️
.../kit/components/input-date/input-date.component.ts 85.52% <0.00%> (+1.11%) ⬆️
...onents/color-selector/palette/palette.component.ts 85.71% <0.00%> (-14.29%) ⬇️
...omponents/editor-socket/editor-socket.component.ts 28.57% <0.00%> (-4.77%) ⬇️
...addon-editor/components/editor/editor.component.ts 28.26% <0.00%> (-1.29%) ⬇️
...don-editor/components/toolbar/toolbar.component.ts 12.94% <0.00%> (-1.17%) ⬇️
...nents/mobile-calendar/mobile-calendar.component.ts 46.03% <0.00%> (-1.08%) ⬇️
.../directives/tiptap-editor/tiptap-editor.service.ts 9.18% <0.00%> (-0.20%) ⬇️
projects/addon-editor/tokens/i18n.ts 100.00% <0.00%> (ø)
projects/kit/components/push/index.ts 100.00% <0.00%> (ø)
... and 38 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@theorlovsky theorlovsky requested review from splincode and removed request for waterplea October 28, 2022 11:03
@splincode splincode requested a review from waterplea October 28, 2022 11:36
@theorlovsky
Copy link
Contributor Author

moved tuiIsPresent pipe to a separate PR #3002

@@ -12,7 +12,7 @@
[disabled]="computedDisabled"
[nativeId]="nativeId"
[readOnly]="readOnly"
[tuiTextfieldIcon]="calendarIcon"
[tuiTextfieldIcon]="calendarIcon ? calendarIcon : null"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about :))

[tuiTextfieldIcon]="calendarIcon | tuiFallback: null"

where

export class TuiFallbackPipe {
  transform<T, K = T>(value?: T|null, fallback: K): T | K {
    return tuiIsPresent(value) ? value : fallback;
  } 
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind, but I want to here @waterplea's opinion on this one, since it's our favourite topic in this PR 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but again, it doesn't cover a case with an empty string

Copy link
Member

@splincode splincode Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, you can use simple solution

[tuiTextfieldIcon]="calendarIcon ?? null"

instead of

[tuiTextfieldIcon]="calendarIcon ? calendarIcon : null"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, I didn't even think about it for some reason

@@ -225,10 +225,8 @@ export class TuiInputDateComponent
return this.activeItem ? `` : filler;
}

onMobileClick(): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breaking changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a method name changed, yes, but other than that it should work as before, I didn't notice any difference

@theorlovsky
Copy link
Contributor Author

@splincode @waterplea so, everything got a lot simpler. I hope no one will come with an idea of hiding the icon using an empty string, and if they do, I wouldn't consider the result a bug on the Taiga side. so we're free to write as you suggested:

[tuiTextfieldIcon]="calendarIcon && iconContent"

as for this one

[tuiTextfieldIcon]="calendarIcon ? calendarIcon : null"

it can easily be reverted to the original

[tuiTextfieldIcon]="calendarIcon"

@theorlovsky
Copy link
Contributor Author

@splincode since Alex is unavailable now, can we get someone else involved to get two approvals?

@theorlovsky
Copy link
Contributor Author

[tuiTextfieldIcon]="calendarIcon"

@splincode what do you mean?

@splincode
Copy link
Member

@theorlovsky sorry, I mean use [tuiTextfieldIcon]="calendarIcon && iconContent"

@theorlovsky
Copy link
Contributor Author

@theorlovsky sorry, I mean use [tuiTextfieldIcon]="calendarIcon && iconContent"

@splincode I already use it

@splincode
Copy link
Member

@theorlovsky sorry, it's good now

@theorlovsky
Copy link
Contributor Author

@splincode how can we get a second approval here?

@splincode
Copy link
Member

@vladimirpotekhin @nsbarsukov fyi

@waterplea waterplea merged commit 27c2d79 into taiga-family:main Nov 9, 2022
@well-done-bot
Copy link

well-done-bot bot commented Nov 9, 2022

'Well done'

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

Successfully merging this pull request may close these issues.

🐞 - Calendar icon in date inputs can be hidden, but it still occupies its space
3 participants