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

feat(addon-doc): adds keybindings to the search field #8830

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChangeDetectorRef,
Component,
inject,
ViewChild,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
Expand Down Expand Up @@ -34,8 +35,7 @@ import {TuiScrollbar} from '@taiga-ui/core/components/scrollbar';
import {TuiTextfield} from '@taiga-ui/core/components/textfield';
import {TUI_COMMON_ICONS} from '@taiga-ui/core/tokens';
import {TuiAccordion} from '@taiga-ui/kit/components/accordion';
import type {TuiInputComponent} from '@taiga-ui/legacy/components/input';
import {TuiInputModule} from '@taiga-ui/legacy/components/input';
import {TuiInputComponent, TuiInputModule} from '@taiga-ui/legacy/components/input';
import {TuiTextfieldControllerModule} from '@taiga-ui/legacy/directives/textfield-controller';
import {PolymorpheusOutlet, PolymorpheusTemplate} from '@taiga-ui/polymorpheus';
import {combineLatest, filter, map, switchMap, take} from 'rxjs';
Expand Down Expand Up @@ -79,9 +79,13 @@ import {TuiDocScrollIntoViewLink} from './scroll-into-view.directive';
providers: NAVIGATION_PROVIDERS,
host: {
'[class._open]': 'menuOpen',
'(window:keydown)': 'onFocusSearch($event)',
},
})
export class TuiDocNavigation {
@ViewChild(TuiInputComponent, {static: true})
private readonly searchInput?: TuiInputComponent;

private readonly router = inject(Router);
private readonly doc = inject(DOCUMENT);

Expand Down Expand Up @@ -165,6 +169,16 @@ export class TuiDocNavigation {
this.openActivePageGroup();
}

protected onFocusSearch(event: KeyboardEvent): void {
if (
event.code === 'Slash' &&
waterplea marked this conversation as resolved.
Show resolved Hide resolved
!(this.doc.activeElement instanceof HTMLInputElement)
waterplea marked this conversation as resolved.
Show resolved Hide resolved
) {
this.searchInput?.nativeFocusableElement?.focus();
event.preventDefault();
}
}

@tuiPure
private filterItems(
items: ReadonlyArray<readonly TuiDocRoutePage[]>,
Expand Down
11 changes: 11 additions & 0 deletions projects/addon-doc/components/navigation/navigation.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
::ng-deep tui-icon {
border: 0.25rem solid transparent;
}

.t-search-text {
display: flex;
flex-direction: row;
justify-content: space-between;

.t-slash {
block-size: 1rem;
font-size: 0.5rem;
}
}
}

.t-navigation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
[tuiTextfieldIconLeft]="docIcons.search"
[tuiTextfieldLabelOutside]="true"
>
{{ searchText }}
<div class="t-search-text">
{{ searchText }}
<code class="t-slash">/</code>
</div>
<ng-container *ngIf="canOpen">
<tui-data-list *tuiDataList>
<tui-opt-group
Expand Down
Loading