-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(addon-mobile): fix minLength and maxLength properties for range i…
…n mobile calendar (#9118) Co-authored-by: l.golovina <[email protected]>
- Loading branch information
Showing
5 changed files
with
99 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...s/addon-mobile/components/mobile-calendar-dropdown/mobile-calendar-dropdown.template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
<tui-mobile-calendar | ||
[disabledItemHandler]="disabledItemHandler" | ||
[max]="max" | ||
[min]="min" | ||
[disabledItemHandler]="calculatedDisabledItemHandler" | ||
[max]="max()" | ||
[min]="min()" | ||
[multi]="multi" | ||
[single]="single" | ||
(cancel)="close()" | ||
(confirm)="confirm($event)" | ||
(valueChange)="onValueChange($event)" | ||
/> |
22 changes: 22 additions & 0 deletions
22
projects/kit/components/calendar-range/calculate-disabled-item-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type {TuiDay, TuiDayLike, TuiDayRange} from '@taiga-ui/cdk/date-time'; | ||
import type {TuiBooleanHandler} from '@taiga-ui/cdk/types'; | ||
|
||
export const calculateDisabledItemHandler: ( | ||
disabledItemHandler: TuiBooleanHandler<TuiDay>, | ||
value: TuiDayRange | null, | ||
minLength: TuiDayLike | null, | ||
) => TuiBooleanHandler<TuiDay> = (disabledItemHandler, value, minLength) => (item) => { | ||
if (!value?.isSingleDay || !minLength) { | ||
return disabledItemHandler(item); | ||
} | ||
|
||
const negativeMinLength = Object.fromEntries( | ||
Object.entries(minLength).map(([key, value]) => [key, -value]), | ||
); | ||
const disabledBefore = value.from.append(negativeMinLength).append({day: 1}); | ||
const disabledAfter = value.from.append(minLength).append({day: -1}); | ||
const inDisabledRange = | ||
disabledBefore.dayBefore(item) && disabledAfter.dayAfter(item); | ||
|
||
return inDisabledRange || disabledItemHandler(item); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './calculate-disabled-item-handler'; | ||
export * from './calendar-range.component'; | ||
export * from './day-caps-mapper'; | ||
export * from './day-range-period'; |