-
Notifications
You must be signed in to change notification settings - Fork 485
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
Conversation
@@ -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" |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;
}
projects/kit/components/input-date-time/input-date-time.template.html
Outdated
Show resolved
Hide resolved
Pull request was closed ✔️All saved screenshots (for current PR) were deleted 🗑️ |
I forgot to add docs for |
BundleMonFiles updated (1)
Unchanged files (4)
Total files change -178B -0.03% Groups updated (1)
Final result: ✅ View report in BundleMon website ➡️ |
Codecov ReportBase: 61.79% // Head: 61.89% // Increases project coverage by
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
Flags with carried forward coverage won't be shown. Click here to find out 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. |
moved |
@@ -12,7 +12,7 @@ | |||
[disabled]="computedDisabled" | |||
[nativeId]="nativeId" | |||
[readOnly]="readOnly" | |||
[tuiTextfieldIcon]="calendarIcon" | |||
[tuiTextfieldIcon]="calendarIcon ? calendarIcon : null" |
There was a problem hiding this comment.
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;
}
}
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breaking changes?
There was a problem hiding this comment.
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
@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" |
@splincode since Alex is unavailable now, can we get someone else involved to get two approvals? |
@splincode what do you mean? |
@theorlovsky sorry, I mean use |
@splincode I already use it |
@theorlovsky sorry, it's good now |
@splincode how can we get a second approval here? |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
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?