diff --git a/content/ui/searchbar.md b/content/ui/searchbar.md new file mode 100644 index 00000000..575e3eca --- /dev/null +++ b/content/ui/searchbar.md @@ -0,0 +1,244 @@ +--- +title: SearchBar +--- + + +`` is a UI component that provides a user interface for entering search queries and submitting requests to the search provider. + +--- +
+
+
+ Android SearchBar Example +
+ +
+iOS SearchBar Example +
+
+
+ + +### A simple SearchBar handling the clear and submit events + +```xml + +``` + +```ts +import { Observable, Page, SearchBar } from '@nativescript/core' + +export function onNavigatingTo(args) { + const page = args.object as Page + const vm = new HelloWorldModel() + page.bindingContext = vm +} + +export class HelloWorldModel extends Observable { + searchText= "" + constructor() { + super() + } + + onSearchBarLoaded(args: EventData){ + const searchBar = args.object as SearchBar; + searchBar.on("textChange",(args: PropertyChangeData)=>{ + + console.log("Event name: ",args.eventName) +}) + } +onSubmit(args: EventData) { + const searchBar = args.object as SearchBar + console.log(`Searching for ${searchBar.text}`) + } + + onClear(args: EventData) { + const searchBar = args.object as SearchBar + console.log(`Clear event raised`) + } +} +``` + + + +## Props + +### hint +```xml + +``` +Gets or sets placeholder text for the input area. + +--- +### text +```xml + +``` +Gets or sets the value of the search query. + +--- +### textFieldBackgroundColor +```xml + +``` +Gets or sets the background color of the input area. + +--- +### textFieldHintColor +```xml + +``` +Gets or sets the color of the placeholder text. + +--- +### ...Inherited +For additional inherited properties, refer to the [API Reference](https://docs.nativescript.org/api-reference/classes/searchbar) + +## Event(s) +### textChange +```ts +searchBar.on("textChange", (args: PropertyChangeData) => { + + console.log("Event name: ", args.oldValue) + + }) +``` +Emitted when the search text is changed. + +--- +### submit +```xml + +``` +```ts +export class HelloWorldModel extends Observable { + onSubmit(args: EventData) { + const searchBar = args.object as SearchBar + console.log(`Searching for ${searchBar.text}`) + } +} +``` +Emitted when the search text is submitted. + +--- +### clear +```xml + +``` +```ts +export class HelloWorldModel extends Observable { + + onClear(args: EventData) { + const searchBar = args.object as SearchBar + console.log(`Clear event raised`) + } +} +``` +Emitted when the current search input is cleared through the **X** button in the input area. + +--- + +## Native Component + +| Android | iOS | +| ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | +| [`android.widget.SearchView`](https://developer.android.com/reference/android/widget/SearchView.html) | [`UISearchBar`](https://developer.apple.com/documentation/uikit/uisearchbar) |