Skip to content

Commit

Permalink
typeahead adaptive position
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronpettit committed Feb 8, 2024
1 parent db13b3e commit 2f75a87
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<input #typeaheadInput autocomplete="off" [hidden]="!isOpen.value" [(ngModel)]="currentDisplay" [placeholder]="placeholder ? placeholder : ''"
(ngModelChange)="matchControlToInput()" [typeahead]="selectionListItems" (typeaheadOnSelect)="selected()"
typeaheadOptionField="display" [optionsListTemplate]="getTemplate()" [typeaheadMinLength]="typeaheadMinLength"
[adaptivePosition]="true" [disabled]="isDisabled" class="w-100 h-100 rounded border-0 multiselect-input"
[adaptivePosition]="adaptivePosition" [disabled]="isDisabled" class="w-100 h-100 rounded border-0 multiselect-input"
[ngClass]="{'is-invalid': isInvalid, 'shrink-input': !isOpen.value}" (focus)="onFocus()" (blur)="onBlur()" [attr.id]="control?.id">
<!-- Placeholder -->
<div class="text-muted text-start" *ngIf="multiselect && placeholder && !control.value && !isFocused">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { BehaviorSubject } from 'rxjs';
export class NgdsTypeaheadInput extends NgdsInput implements AfterViewInit {
// The minimum length that must be typed before suggestion dropdown appears. If 0, dropdown opens on select.
@Input() typeaheadMinLength: number = 0;
// The typeahead options will drop up or drop down unless this is set to false.
@Input() adaptivePosition: boolean = true;

@ViewChild('defaultListTemplate') defaultListTemplate: TemplateRef<any>;
@ViewChild('typeaheadInput') typeaheadInput: ElementRef;
Expand Down
5 changes: 4 additions & 1 deletion src/app/forms/typeaheads/typeaheads.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ <h3>Basic Typeahead</h3>
<p>
Provide the list of selection options as an array in <code>[selectionListItems]</code>, same as the picklist input. NGDS Forms Typeahead extends the functionality of the typeahead provided in <a href="https://valor-software.com/ngx-bootstrap/#/components/typeahead" target="_blank" rel="noopener">ngx-bootstrap</a>.
</p>
<p>
Use <code>[adaptivePosition]="false"</code> to force the suggestions to dropdown.
</p>
<p>
In the example below, search for a Canadian province or territory.
</p>
Expand All @@ -21,7 +24,7 @@ <h3>Set typeahead value programmatically</h3>
<demonstrator [htmlFile]="snippets?.programmaticTypeahead?.html" [tsFile]="snippets?.programmaticTypeahead?.ts"
[control]="form?.controls?.['programmaticTypeahead']">
<button class="btn btn-primary mb-2" (click)="programmaticSet()">Set value</button>
<ngds-typeahead-input [control]="form?.controls?.['programmaticTypeahead']" [selectionListItems]="displayProvinceList">
<ngds-typeahead-input [control]="form?.controls?.['programmaticTypeahead']" [selectionListItems]="displayProvinceList" [adaptivePosition]="false">
</ngds-typeahead-input>
</demonstrator>
</section>
Expand Down

0 comments on commit 2f75a87

Please sign in to comment.