Skip to content

Commit

Permalink
fix(kit): correct present of control value from items list for input-…
Browse files Browse the repository at this point in the history
…time
  • Loading branch information
splincode committed Aug 5, 2024
1 parent c1d2160 commit 29fd682
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class TuiOptionComponent<T = unknown> implements OnDestroy {
onClick(): void {
if (this.host && this.value !== undefined) {
this.host.handleOption(this.value);
this.el.nativeElement.focus();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ExampleTuiInputTimeComponent extends AbstractExampleTuiControl {

override cleaner = false;

control = new FormControl(TuiTime.currentLocal(), Validators.required);
control = new FormControl(new TuiTime(15, 30), Validators.required);

readonly disabledItemHandlerVariants: ReadonlyArray<TuiBooleanHandler<TuiTime>> = [
ALWAYS_FALSE_HANDLER,
Expand Down
6 changes: 6 additions & 0 deletions projects/kit/components/input-time/input-time.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ export class TuiInputTimeComponent
this.processArrow(event, -1);
}

checkOption(option: TuiTime): void {
if (option.toAbsoluteMilliseconds() === this.value?.toAbsoluteMilliseconds()) {
this.value = option;
}
}

handleOption(item: TuiTime): void {
this.focusInput();
this.value = item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class TuiSelectOptionComponent<T> implements OnInit, DoCheck {
void Promise.resolve().then(() => {
if (tuiIsPresent(this.option.value) && !this.option.disabled) {
this.host.checkOption?.(this.option.value);
this.el.nativeElement.focus();
}
});
}
Expand Down

0 comments on commit 29fd682

Please sign in to comment.