Skip to content

Commit 03daa29

Browse files
committed
Add PickerField element selector
Add PickerPage element that inherits from Page in the modal and a selector for it Move the class set on ActionBar and ListView to the aforementioned PickerPage Document it
1 parent 18d0a9d commit 03daa29

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ The `PickerField` is a NativeScript `TextField` which means that any functionali
9595
## Styling
9696
9797
### PickerField
98-
The `PickerField` inherits from the `TextField` class of the `tns-core-modules/ui/text-field/text-field` module which means all of the available styling of `TextField` are available directly. Additionally the `PickerField` opens a modal window contains a `ListView` instance which inherits the css class of the `PickerField` meaning you can style that ListView elements with the use of `ListView.<your-class-name>` and simply set the `class` of the `PickerField` to `your-class-name`. The modal window also contains its own ActionBar which again inherits the css class of the `PickerField` and can be styling the same way as described above for the ListView. For full list of the available properties of which many can be styling/set via css you can refer the official API documentation of ListView [here](https://docs.nativescript.org/api-reference/modules/_ui_list_view_).
98+
The `PickerField` can be targeted in CSS through its element selector and additionally by setting a class. The `PickerField` also opens a modal window containing a Page element that contains an ActionBar and a ListView. This Page element can be targeted with the `PickerPage` selector and through it style all picker modals with selectors like `PickerPage ActionBar` and `PickerPage ListView`. In addition to that, if you set a class on the PickerField, it will be transferred on the `PickerPage` and with it you can style individual modals.
9999
100100
## Contribute
101101
We love PRs! Check out the [contributing guidelines](https://github.com/NativeScript/nativescript-picker/blob/master/CONTRIBUTING.md). If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/nativescript-picker/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).

src/picker.common.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Observable } from 'tns-core-modules/data/observable';
2-
import { Property, Template, booleanConverter } from "tns-core-modules/ui/core/view/view";
2+
import { Property, Template, booleanConverter, CSSType } from "tns-core-modules/ui/core/view/view";
33
import { View, EventData } from "tns-core-modules/ui/core/view/view";
44
import { TextField } from 'tns-core-modules/ui/text-field/text-field';
55
import { Button } from 'tns-core-modules/ui/button/button';
@@ -28,6 +28,11 @@ export interface PickerField {
2828
on(event: "itemLoading", callback: (args: ItemEventData) => void, thisArg?: any);
2929
}
3030

31+
// Allow targeting PickerPage through CSS element selector
32+
@CSSType("PickerPage")
33+
export class PickerPage extends Page {}
34+
35+
@CSSType("PickerField")
3136
export class PickerField extends TextField implements TemplatedItemsView {
3237

3338
public static itemLoadingEvent = "itemLoading";
@@ -62,7 +67,7 @@ export class PickerField extends TextField implements TemplatedItemsView {
6267

6368
private createModalView() {
6469
this._modalRoot = new Frame();
65-
this._page = new Page();
70+
this._page = new PickerPage();
6671
this._modalListView = new ListView();
6772
this._modalGridLayout = new GridLayout();
6873
this.initModalView();
@@ -80,15 +85,15 @@ export class PickerField extends TextField implements TemplatedItemsView {
8085
}
8186

8287
private initModalView() {
88+
this.applyCssScope(this._page);
89+
8390
if (this.pickerTitle && this.pickerTitle !== "") {
8491
this._page.actionBar.title = this.pickerTitle;
8592
} else {
8693
this._modalRoot.actionBarVisibility = "always";
8794
this._page.actionBar.title = "";
8895
}
8996

90-
this.applyCssScope(this._page.actionBar);
91-
9297
let actionItem = new ActionItem();
9398
actionItem.text = "Close";
9499
actionItem.on(Button.tapEvent, (args: ItemEventData) => {
@@ -111,7 +116,6 @@ export class PickerField extends TextField implements TemplatedItemsView {
111116

112117
this._modalListView.on(ListView.itemLoadingEvent, this.listViewItemLoadingHandler.bind(this));
113118
this._modalListView.on(ListView.itemTapEvent, this.listViewItemTapHandler.bind(this));
114-
this.applyCssScope(this._modalListView);
115119
this._modalListView.items = this.items;
116120

117121
(<any>this._modalGridLayout).addChild(this._modalListView);

0 commit comments

Comments
 (0)