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 Jul 29, 2024
1 parent 276879b commit 81dfd3b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class TuiOptionComponent<T = unknown> implements OnDestroy {
@HostListener('click')
onClick(): void {
if (this.host && this.value !== undefined) {
this.host.handleOption(this.value);
this.host.handleOption(this.value, this.el.nativeElement);
}
}

Expand Down
4 changes: 2 additions & 2 deletions projects/core/interfaces/data-list-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {TuiIdentityMatcher, TuiStringHandler} from '@taiga-ui/cdk';

// TODO: Consider refactoring checkOption, it is only needed in ComboBox
export interface TuiDataListHost<T> {
checkOption?(option: T): void;
handleOption(option: T): void;
checkOption?(option: T, element: HTMLElement): void;
handleOption(option: T, element: HTMLElement): void;
readonly identityMatcher?: TuiIdentityMatcher<T>;
readonly stringify?: TuiStringHandler<T>;
}
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
7 changes: 7 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,13 @@ export class TuiInputTimeComponent
this.processArrow(event, -1);
}

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

handleOption(item: TuiTime): void {
this.focusInput();
this.value = item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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.host.checkOption?.(this.option.value, this.el.nativeElement);
}
});
}
Expand Down

0 comments on commit 81dfd3b

Please sign in to comment.