SearchBar.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. module INSPECTOR {
  2. /**
  3. * A search bar can be used to filter elements in the tree panel.
  4. * At each keypress on the input, the treepanel will be filtered.
  5. */
  6. export class SearchBar extends BasicElement {
  7. private _tab : PropertyTab;
  8. private _inputElement: HTMLInputElement;
  9. constructor(tab:PropertyTab) {
  10. super();
  11. this._tab = tab;
  12. this._div.classList.add('searchbar');
  13. let filter = Inspector.DOCUMENT.createElement('i');
  14. filter.className = 'fa fa-search';
  15. this._div.appendChild(filter);
  16. // Create input
  17. this._inputElement = Inspector.DOCUMENT.createElement('input');
  18. this._inputElement.placeholder = 'Filter by name...';
  19. this._div.appendChild(this._inputElement);
  20. this._inputElement.addEventListener('keyup', (evt : KeyboardEvent)=> {
  21. let filter = this._inputElement.value;
  22. this._tab.filter(filter);
  23. })
  24. }
  25. /** Delete all characters typped in the input element */
  26. public reset() {
  27. this._inputElement.value = '';
  28. }
  29. public update() {
  30. // Nothing to update
  31. }
  32. }
  33. }