Skip to main content

SearchBox

A search box provides an input field for searching content within a site or app to find specific items.

Examples​

Live demo

Basic searchboxes​

import pglet
from pglet import SearchBox
with pglet.page("basic-searchboxes") as page:
page.add(
SearchBox(),
SearchBox(underlined=True, placeholder='Underlined SearchBox'),
SearchBox(disabled=True, placeholder='Disabled SearchBox'),
SearchBox(placeholder='SearchBox with icon', icon='Filter', icon_color='red'))

SearchBox with search, clear and escape events​

import pglet
from pglet import SearchBox, Stack, Text

with pglet.page("searchbox-with-search-clear-and-escape-events") as page:

def enter_clicked(e):
messages.controls.append(Text(f'You have searched for {sb.value}.'))
sb.value = ''
page.update()

def clear_or_esc_clicked(e):
sb.value = ''
messages.controls.append(Text('You have cleared the box.'))
page.update()

sb = SearchBox(width=300, placeholder='Search something and click Enter, X or Esc', on_search=enter_clicked, on_clear=clear_or_esc_clicked)
messages = Stack()

page.add(sb, messages)

input()

SearchBox with change event​

import pglet
from pglet import SearchBox, Text

with pglet.page("searchbox-with-change-event") as page:

def searchbox_changed(e):
t.value = f'You have searched for {sb.value}.'
page.update()

sb = SearchBox(placeholder='Search something...', on_change=searchbox_changed)
t = Text()

page.add(sb, t)

input()

Properties​

NameTypeDefaultDescription
valuestringThe value of the text in the SearchBox.
placeholderstringPlaceholder for the search box.
underlinedboolfalseWhether or not the SearchBox is underlined.
iconstringReplace "search" icon with a custom one.
iconColorstringIcon color.
focusedboolfalseWhen set to true the focus is set on the control when it's shown on the page or page opened.
datastringAdditional data attached to the control. The value is passed in event data.
onChangeboolfalseWhether change event should be fired while text is typed into the SearchBox. This property is used by command-based client libraries only, e.g. Bash.

Events​

NameDescription
searchFires when the user presses Enter in the search box.
clearFires when the user clears the search box by either clicking 'X' or hitting escape.
changeFires when the typed input for the SearchBox has changed. For performance optimization this event is disabled unless onChange property set to true.
focusFires when the control has received focus.
blurFires when the control has lost focus.