-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit):
Select
add ability to use native select on mobile (#2964)
- Loading branch information
1 parent
32c8736
commit c909bec
Showing
16 changed files
with
277 additions
and
5 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
27 changes: 27 additions & 0 deletions
27
projects/demo/src/modules/components/select/examples/11/index.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<form class="b-form"> | ||
<tui-select [formControl]="itemControl"> | ||
Character | ||
<select | ||
tuiSelect | ||
[items]="items" | ||
></select> | ||
</tui-select> | ||
|
||
<tui-select | ||
class="tui-space_top-4" | ||
[formControl]="itemGroupControl" | ||
[tuiTextfieldCleaner]="true" | ||
> | ||
Food | ||
<select | ||
tuiSelect | ||
[items]="groupItems" | ||
[labels]="labels" | ||
></select> | ||
|
||
<input | ||
tuiTextfield | ||
placeholder="Make a choice" | ||
/> | ||
</tui-select> | ||
</form> |
31 changes: 31 additions & 0 deletions
31
projects/demo/src/modules/components/select/examples/11/index.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,31 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
|
||
@Component({ | ||
selector: `tui-select-example-11`, | ||
templateUrl: `./index.html`, | ||
changeDetection, | ||
encapsulation, | ||
}) | ||
export class TuiSelectExample11 { | ||
itemControl = new FormControl(); | ||
itemGroupControl = new FormControl(); | ||
|
||
items = [ | ||
`Luke Skywalker`, | ||
`Leia Organa Solo`, | ||
`Darth Vader`, | ||
`Han Solo`, | ||
`Obi-Wan Kenobi`, | ||
`Yoda`, | ||
]; | ||
|
||
groupItems = [ | ||
[`Caesar`, `Greek`, `Apple and Chicken`], | ||
[`Broccoli Cheddar`, `Chicken and Rice`, `Chicken Noodle`], | ||
]; | ||
|
||
labels = [`Salad`, `Soup`]; | ||
} |
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
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
42 changes: 42 additions & 0 deletions
42
projects/kit/components/select/native-select/native-select-group.component.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,42 @@ | ||
import {ChangeDetectionStrategy, Component, Input, TemplateRef} from '@angular/core'; | ||
import {TuiDataListDirective} from '@taiga-ui/core'; | ||
|
||
import {AbstractTuiNativeSelect} from './native-select'; | ||
|
||
@Component({ | ||
selector: `select[tuiSelect][labels]`, | ||
templateUrl: `./native-select-group.template.html`, | ||
providers: [ | ||
{ | ||
provide: TuiDataListDirective, | ||
deps: [TuiNativeSelectGroupComponent], | ||
useExisting: TuiNativeSelectGroupComponent, | ||
}, | ||
{ | ||
provide: TemplateRef, | ||
deps: [TuiNativeSelectGroupComponent], | ||
useFactory: ({datalist}: TuiNativeSelectGroupComponent) => datalist, | ||
}, | ||
{ | ||
provide: AbstractTuiNativeSelect, | ||
useExisting: TuiNativeSelectGroupComponent, | ||
}, | ||
], | ||
host: { | ||
'[attr.aria-invalid]': `host.invalid`, | ||
'[disabled]': `host.disabled`, | ||
'[tabIndex]': `host.focusable ? 0 : -1`, | ||
'[readOnly]': `host.readOnly`, | ||
'[value]': `host.value`, | ||
'(change)': `host.onValueChange($event.target.value)`, | ||
}, | ||
styleUrls: [`./native-select.style.less`], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class TuiNativeSelectGroupComponent extends AbstractTuiNativeSelect { | ||
@Input() | ||
items: readonly string[][] | null = []; | ||
|
||
@Input() | ||
labels: readonly string[] = []; | ||
} |
16 changes: 16 additions & 0 deletions
16
projects/kit/components/select/native-select/native-select-group.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<tui-data-list-wrapper | ||
*tuiDataList | ||
[items]="items" | ||
[labels]="labels" | ||
></tui-data-list-wrapper> | ||
<optgroup | ||
*ngFor="let group of items; let index = index" | ||
[label]="labels[index]" | ||
> | ||
<option | ||
*ngFor="let option of group" | ||
[value]="option" | ||
> | ||
{{ option }} | ||
</option> | ||
</optgroup> |
39 changes: 39 additions & 0 deletions
39
projects/kit/components/select/native-select/native-select.component.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,39 @@ | ||
import {ChangeDetectionStrategy, Component, Input, TemplateRef} from '@angular/core'; | ||
import {TuiDataListDirective} from '@taiga-ui/core'; | ||
|
||
import {AbstractTuiNativeSelect} from './native-select'; | ||
|
||
@Component({ | ||
selector: `select[tuiSelect]:not([labels])`, | ||
templateUrl: `./native-select.template.html`, | ||
providers: [ | ||
{ | ||
provide: TuiDataListDirective, | ||
deps: [TuiNativeSelectComponent], | ||
useExisting: TuiNativeSelectComponent, | ||
}, | ||
{ | ||
provide: TemplateRef, | ||
deps: [TuiNativeSelectComponent], | ||
useFactory: ({datalist}: TuiNativeSelectComponent) => datalist, | ||
}, | ||
{ | ||
provide: AbstractTuiNativeSelect, | ||
useExisting: TuiNativeSelectComponent, | ||
}, | ||
], | ||
host: { | ||
'[attr.aria-invalid]': `host.invalid`, | ||
'[disabled]': `host.disabled`, | ||
'[tabIndex]': `host.focusable ? 0 : -1`, | ||
'[readOnly]': `host.readOnly`, | ||
'[value]': `host.value`, | ||
'(change)': `host.onValueChange($event.target.value)`, | ||
}, | ||
styleUrls: [`./native-select.style.less`], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class TuiNativeSelectComponent extends AbstractTuiNativeSelect { | ||
@Input() | ||
items: readonly string[] | null = []; | ||
} |
6 changes: 6 additions & 0 deletions
6
projects/kit/components/select/native-select/native-select.style.less
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,6 @@ | ||
@import 'taiga-ui-local'; | ||
|
||
:host { | ||
.fullsize(); | ||
opacity: 0; | ||
} |
10 changes: 10 additions & 0 deletions
10
projects/kit/components/select/native-select/native-select.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<tui-data-list-wrapper | ||
*tuiDataList | ||
[items]="items" | ||
></tui-data-list-wrapper> | ||
<option | ||
*ngFor="let option of items" | ||
[value]="option" | ||
> | ||
{{ option }} | ||
</option> |
30 changes: 30 additions & 0 deletions
30
projects/kit/components/select/native-select/native-select.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,30 @@ | ||
import { | ||
Directive, | ||
ElementRef, | ||
HostBinding, | ||
Inject, | ||
TemplateRef, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import {TuiIdService} from '@taiga-ui/cdk'; | ||
import {TUI_TEXTFIELD_HOST, TuiDataListDirective, TuiTextfieldHost} from '@taiga-ui/core'; | ||
|
||
@Directive() | ||
export abstract class AbstractTuiNativeSelect { | ||
@ViewChild(TuiDataListDirective, {read: TemplateRef, static: true}) | ||
readonly datalist: TemplateRef<any> | null = null; | ||
|
||
constructor( | ||
@Inject(TUI_TEXTFIELD_HOST) readonly host: TuiTextfieldHost, | ||
@Inject(ElementRef) private readonly elementRef: ElementRef<HTMLInputElement>, | ||
@Inject(TuiIdService) | ||
private readonly idService: TuiIdService, | ||
) { | ||
this.host.process(this.elementRef.nativeElement); | ||
} | ||
|
||
@HostBinding(`id`) | ||
get id(): string { | ||
return this.elementRef.nativeElement.id || this.idService.generate(); | ||
} | ||
} |
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
Oops, something went wrong.