@brightspace-ui/core 2.76.3 → 2.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,14 @@
28
28
  </template>
29
29
  </d2l-demo-snippet>
30
30
 
31
+ <h2>Search Input (Search on Input)</h2>
32
+ <d2l-demo-snippet>
33
+ <template>
34
+ <d2l-input-search label="Search" value="Will dispatch search after every input" placeholder="Search for some stuff" search-on-input>
35
+ </d2l-input-search>
36
+ </template>
37
+ </d2l-demo-snippet>
38
+
31
39
  <script>
32
40
  document.body.addEventListener('d2l-input-search-searched', (e) => {
33
41
  // eslint-disable-next-line no-console
@@ -60,6 +60,7 @@ For text searches use `<d2l-input-search>`, which wraps the native `<input type=
60
60
  | `disabled` | Boolean | Disables the input |
61
61
  | `maxlength` | Number | Imposes an upper character limit |
62
62
  | `no-clear` | Boolean | Prevents the "clear" button from appearing |
63
+ | `search-on-input` | Boolean | Dispatch search events after each input event |
63
64
  | `placeholder` | String, default:`'Search...'` | Placeholder text |
64
65
  | `value` | String, default: `''` | Value of the input |
65
66
 
@@ -8,6 +8,8 @@ import { inputStyles } from './input-styles.js';
8
8
  import { LocalizeCoreElement } from '../../helpers/localize-core-element.js';
9
9
  import { RtlMixin } from '../../mixins/rtl-mixin.js';
10
10
 
11
+ const INPUT_TIMEOUT_MS = 400;
12
+
11
13
  /**
12
14
  * This component wraps the native "<input type="search">"" element and is for text searching.
13
15
  * @fires d2l-input-search-searched - Dispatched when a search is performed. When the input is cleared, this will be fired with an empty value.
@@ -50,6 +52,11 @@ class InputSearch extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement)))
50
52
  * @type {string}
51
53
  */
52
54
  placeholder: { type: String },
55
+ /**
56
+ * Dispatch search events after each input event
57
+ * @type {boolean}
58
+ */
59
+ searchOnInput: { type: Boolean, attribute: 'search-on-input' },
53
60
  /**
54
61
  * Value of the input
55
62
  * @type {string}
@@ -81,9 +88,11 @@ class InputSearch extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement)))
81
88
 
82
89
  constructor() {
83
90
  super();
91
+ this._inputTimeout = undefined;
84
92
  this._lastSearchValue = '';
85
93
  this.disabled = false;
86
94
  this.noClear = false;
95
+ this.searchOnInput = false;
87
96
  this.value = '';
88
97
  }
89
98
 
@@ -151,6 +160,12 @@ class InputSearch extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement)))
151
160
  return showSearch;
152
161
  }
153
162
 
163
+ _debounceInput() {
164
+ clearTimeout(this._inputTimeout);
165
+ this._setLastSearchValue(this.value);
166
+ this._inputTimeout = setTimeout(() => this._dispatchEvent(), INPUT_TIMEOUT_MS);
167
+ }
168
+
154
169
  _dispatchEvent() {
155
170
  this.dispatchEvent(new CustomEvent(
156
171
  'd2l-input-search-searched',
@@ -169,6 +184,9 @@ class InputSearch extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement)))
169
184
 
170
185
  _handleInput(e) {
171
186
  this.value = e.target.value;
187
+ if (this.searchOnInput) {
188
+ this._debounceInput();
189
+ }
172
190
  }
173
191
 
174
192
  _handleInputKeyPress(e) {
@@ -5999,6 +5999,12 @@
5999
5999
  "type": "boolean",
6000
6000
  "default": "false"
6001
6001
  },
6002
+ {
6003
+ "name": "search-on-input",
6004
+ "description": "Dispatch search events after each input event",
6005
+ "type": "boolean",
6006
+ "default": "false"
6007
+ },
6002
6008
  {
6003
6009
  "name": "value",
6004
6010
  "description": "Value of the input",
@@ -6049,6 +6055,13 @@
6049
6055
  "type": "boolean",
6050
6056
  "default": "false"
6051
6057
  },
6058
+ {
6059
+ "name": "searchOnInput",
6060
+ "attribute": "search-on-input",
6061
+ "description": "Dispatch search events after each input event",
6062
+ "type": "boolean",
6063
+ "default": "false"
6064
+ },
6052
6065
  {
6053
6066
  "name": "value",
6054
6067
  "attribute": "value",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.76.3",
3
+ "version": "2.77.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",