Search Bar

Purpose

Provides support for the search bar construct.

The search bar consists of three parts laid out in the following order.

  1. An optional logo, represented using the object element.

  2. A text input control, represented using the xforms:input element.

  3. A submit button, represented using the xforms:submit element.

There are three rendering strategies of the search bar construct. The following strategies are listed in the order of preference, i.e. the first rendering that the device can support is the one that should be used for that device.

  1. The Flexible rendering strategy

  2. The Fixed No Wrap rendering strategy

  3. The Fixed Wrap rendering strategy

Exported Features
Note:

The cf2:ui.SearchBar#FixedWrap feature always returns false and is reserved for future product enhancements.

Imported Features

n/a

The cf2:ui.SearchBar feature is the union of the features for each strategy, and it is assumed to be supported if any of the sub features are supported. The sub features are mutually exclusive, i.e. a device that supports cf2:ui.SearchBar#Flexible cannot also support one of the other sub features. The set of devices that support cf2:ui.SearchBar is the union of the sets of devices that support each of the strategy specific features.

Markup

This component is provided by the ui:search-bar element.

The Flexible rendering strategy

This is the ideal representation of the search bar construct. Each part of the bar is centered vertically within the line. The bar occupies a single line, and fills the width of the page but does not overflow its edge, i.e. the text input field expands or contracts depending upon the width of the device screen.

The use of this strategy places a number of restrictions on the search bar elements. Refer to the section entitled Constraints for more information.

SearchBar - Flexible

The Fixed No Wrap rendering strategy

The Fixed No Wrap and Fixed Wrap strategies are capable of handling the search bar construct on devices that do not support the Flexible rendering strategy. However, the search bar may no longer occupy the full width of the screen, and the search bar logo is ignored. The use of this strategy places a number of restrictions on the search bar elements. Please refer to the section entitled Constraints for more information.

The following table explains the relationship between the value of the text-align property set on the ui:search-bar element and the layout of the search bar.

text-align Search bar layout
left
SearchBar - Fixed No Wrap
right
SearchBar - Fixed No Wrap
center
SearchBar - Fixed No Wrap
justify
SearchBar - Fixed No Wrap

The Fixed Wrap rendering strategy

This strategy is used when the device supports the Fixed No Wrap strategy but the calculated width of the input field is less than the width defined by the min-width property. Again, the search bar may no longer occupy the full width of the screen, the logo is ignored, and the use of this strategy places a number of constraints on the search bar elements. Refer to the section entitled Constraints for details.

The following table explains the relationship between the value of the text-align property set on the ui:search-bar element and the layout of the search bar.

text-align Search bar layout
left
SearchBar - Fixed Wrap
right
SearchBar - Fixed Wrap
center
SearchBar - Fixed Wrap

Constraints

There are a number of constraints that apply to the search bar elements.

The following styles are common to all strategies. If the page author violates these constraints, then it is a non fatal error, in other words, an error message will be logged to explain which constraint has been violated and how, and then it will behave as if the constraint was not violated, i.e. the value of the property will be set to the default value.

ui|search-bar {
  width: auto;
  height: auto;
}

ui|search-bar > xforms|input {
  width: auto;
  height: auto;
  mcs-columns: 0;
  mcs-box-sizing: border-box;
}

ui|search-bar > xforms|submit {
  width: auto;
  height: auto;
}

In addition to the common styles the following restrictions apply to the Flexible strategy.

ui|search-bar {
  display: mcs-box;
  overflow: hidden;
  mcs-box-align: center;
}

ui|search-bar > xhtml2|object {
  width: auto;
  height: auto;
  mcs-box-flex: 0;
}

ui|search-bar > xforms|input {
  mcs-box-flex: 1;
}

ui|search-bar > xforms|submit {
  mcs-box-flex: 0;
}

The use of the Fixed No Wrap and Fixed Wrap strategies imposes additional constraints on the search bar elements. Again, it is an error if the page author tries to override any of the properties to different values.

Several general restrictions apply:

Customizing styles

Page authors may not want to restrict devices that support the Flexible strategy to using only those styles that are allowed in the fixed strategy. However, authors cannot just set the styles for all strategies as that will cause the constraints to be violated and will result in errors being logged. Therefore, page authors need to create a separate theme for styling the search bar. That theme must contain one variant for styling the Flexible strategy and use the selection by expression mechanism to target it at those devices that support the cf2:ui.SearchBar#Flexible feature. If authors want to customize the styling of the fixed strategies, then they can add another variant and use selection by expression to target it at devices that support one of the fixed strategies.

Related topics