Skip to content

Commit 15bb349

Browse files
committed
SearchBox: allow focusing on startup via focusOnStartup config prop
1 parent 7f094a3 commit 15bb349

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

components/SearchBox.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SearchBox extends React.Component {
6363
replacePlaceholderLayer: PropTypes.func,
6464
searchOptions: PropTypes.shape({
6565
allowSearchFilters: PropTypes.bool,
66+
focusOnStartup: PropTypes.bool,
6667
hideResultLabels: PropTypes.bool,
6768
highlightStyle: PropTypes.object,
6869
minScaleDenom: PropTypes.number,
@@ -638,7 +639,7 @@ class SearchBox extends React.Component {
638639
onClick={() => this.setState({resultsVisible: true})}
639640
onFocus={this.onFocus}
640641
onKeyDown={this.onKeyDown}
641-
placeholder={placeholder} ref={el => { this.searchBox = el; }}
642+
placeholder={placeholder} ref={this.setSearchBoxRef}
642643
role="input" type="text" value={this.state.searchText} />
643644
{this.state.pendingSearches.length > 0 ? (<Spinner role="suffix" />) : (<Icon icon="clear" onClick={this.clear} role="suffix" />)}
644645
</InputContainer>
@@ -662,6 +663,12 @@ class SearchBox extends React.Component {
662663
)
663664
];
664665
}
666+
setSearchBoxRef = (el) => {
667+
this.searchBox = el;
668+
if (this.props.searchOptions.focusOnStartup) {
669+
el.focus();
670+
}
671+
};
665672
toggleFilterOptions = (visible) => {
666673
this.setState({filterOptionsVisible: visible});
667674
};

doc/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ Top bar, containing the logo, searchbar, task buttons and app menu.
998998
| logoUrl | `string` | The hyperlink to open when the logo is clicked. | `undefined` |
999999
| menuItems | `array` | The menu items. Refer to the corresponding chapter of the viewer documentation and the sample config.json. | `[]` |
10001000
| registerTaskSearchProvider | `bool` | Whether to register a search provider which allows searching menu tasks through the global search field. | `undefined` |
1001-
| searchOptions | `{`<br />`  allowSearchFilters: bool,`<br />`  hideResultLabels: bool,`<br />`  highlightStyle: {`<br />`  strokeColor: array,`<br />`  strokeWidth: number,`<br />`  strokeDash: array,`<br />`  fillColor: array,`<br />`},`<br />`  minScaleDenom: number,`<br />`  resultLimit: number,`<br />`  sectionsDefaultCollapsed: bool,`<br />`  showHighlightMarker: bool,`<br />`  showLayerAfterChangeTheme: bool,`<br />`  showLayerResultsBeforePlaces: bool,`<br />`  showResultInSearchText: bool,`<br />`  zoomToLayers: bool,`<br />`}` | Options passed down to the search component. | `{`<br />`  showHighlightMarker: true,`<br />`  showResultInSearchText: true,`<br />`  minScaleDenom: 1000`<br />`}` |
1001+
| searchOptions | `{`<br />`  allowSearchFilters: bool,`<br />`  focusOnStartup: bool,`<br />`  hideResultLabels: bool,`<br />`  highlightStyle: {`<br />`  strokeColor: array,`<br />`  strokeWidth: number,`<br />`  strokeDash: array,`<br />`  fillColor: array,`<br />`},`<br />`  minScaleDenom: number,`<br />`  resultLimit: number,`<br />`  sectionsDefaultCollapsed: bool,`<br />`  showHighlightMarker: bool,`<br />`  showLayerAfterChangeTheme: bool,`<br />`  showLayerResultsBeforePlaces: bool,`<br />`  showResultInSearchText: bool,`<br />`  zoomToLayers: bool,`<br />`}` | Options passed down to the search component. | `{`<br />`  showHighlightMarker: true,`<br />`  showResultInSearchText: true,`<br />`  minScaleDenom: 1000`<br />`}` |
10021002
| toolbarItems | `array` | The toolbar. Refer to the corresponding chapter of the viewer documentation and the sample config.json. | `[]` |
10031003
| toolbarItemsShortcutPrefix | `string` | The keyboard shortcut prefix for triggering toolbar tasks. I.e. alt+shift. The task are then triggered by <prefix>+{1,2,3,...} for the 1st, 2nd, 3rd... toolbar icon. | `undefined` |
10041004

plugins/TopBar.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class TopBar extends React.Component {
6060
searchOptions: PropTypes.shape({
6161
/** Whether to show the search filter widget. */
6262
allowSearchFilters: PropTypes.bool,
63+
/** Whether to focus the search field on startup. */
64+
focusOnStartup: PropTypes.bool,
6365
/** Whether to hide the result labels on the map. */
6466
hideResultLabels: PropTypes.bool,
6567
/** The style used for highlighting search result geometries. */

0 commit comments

Comments
 (0)