Skip to content

Commit

Permalink
feature(Widgets): placeholder for searchbar can be modified
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed Mar 16, 2022
1 parent c209fdc commit 9bd81ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/widgets_searchbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
const searchbar = new itowns_widgets.Searchbar(view, geocodingOptions, {
// We want to display at maximum 15 location suggestions when typing the searchbar.
maxSuggestionNumber: 15,
placeholder: 'Search a location in France',
});


Expand Down
5 changes: 4 additions & 1 deletion utils/gui/Searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const DEFAULT_OPTIONS = {
position: 'top',
maxSuggestionNumber: 10,
fontSize: 16,
placeholder: 'Search location',
};


Expand Down Expand Up @@ -93,6 +94,8 @@ class Searchbar extends Widget {
* @param {number} [options.fontSize=16] The font size in pixel of the searchbar content.
* @param {number} [options.maxSuggestionNumber=10] The maximum number of suggestions that should
* appear under the searchbar.
* @param {string} [options.placeholder='Search location'] The placeholder that appears in the searchbar
* when nothing has yet been typed.
*/
constructor(view, geocodingOptions, options = {}) {
// ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
Expand Down Expand Up @@ -127,7 +130,7 @@ class Searchbar extends Widget {
const input = document.createElement('input');
input.setAttribute('type', 'text');
input.setAttribute('name', 'mySearch');
input.setAttribute('placeholder', 'Search location');
input.setAttribute('placeholder', options.placeholder || DEFAULT_OPTIONS.placeholder);
input.style.height = `${options.height || options.size || DEFAULT_OPTIONS.height}px`;
input.style.fontSize = `${options.fontSize || DEFAULT_OPTIONS.fontSize}px`;
form.appendChild(input);
Expand Down

0 comments on commit 9bd81ce

Please sign in to comment.