@brightspace-ui/core 3.5.0 → 3.5.2

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.
@@ -225,6 +225,9 @@ class List extends PageableMixin(SelectionMixin(LitElement)) {
225
225
  if (changedProperties.has('add-button') || changedProperties.has('add-button-text')) {
226
226
  this._listChildrenUpdatedSubscribers.updateSubscribers();
227
227
  }
228
+ if (changedProperties.has('grid') && this.grid) {
229
+ this.selectionNoInputArrowKeyBehaviour = true;
230
+ }
228
231
  }
229
232
 
230
233
  getItems(slot) {
@@ -42,6 +42,10 @@ export const SelectionMixin = superclass => class extends RtlMixin(CollectionMix
42
42
 
43
43
  static get properties() {
44
44
  return {
45
+ /**
46
+ * @ignore
47
+ */
48
+ selectionNoInputArrowKeyBehaviour: { type: Boolean, attribute: 'selection-no-input-arrow-key-behavior' },
45
49
  /**
46
50
  * Whether to render with single selection behaviour. If `selection-single` is specified, the nested `d2l-selection-input` elements will render radios instead of checkboxes, and the selection component will maintain a single selected item.
47
51
  * @type {boolean}
@@ -52,6 +56,7 @@ export const SelectionMixin = superclass => class extends RtlMixin(CollectionMix
52
56
 
53
57
  constructor() {
54
58
  super();
59
+ this.selectionNoInputArrowKeyBehaviour = false;
55
60
  this.selectionSingle = false;
56
61
  this._selectAllPages = false;
57
62
  this._selectionObservers = new Map();
@@ -153,7 +158,7 @@ export const SelectionMixin = superclass => class extends RtlMixin(CollectionMix
153
158
  const target = e.composedPath()[0];
154
159
 
155
160
  // check composed path for radio (e.target could be d2l-list-item or other element due to retargeting)
156
- if (!target.classList.contains('d2l-selection-input-radio')) return;
161
+ if (!target.classList.contains('d2l-selection-input-radio') || this.selectionNoInputArrowKeyBehaviour) return;
157
162
  if (e.keyCode < keyCodes.LEFT || e.keyCode > keyCodes.DOWN) return;
158
163
 
159
164
  const getSelectionInput = (focusable, forward) => {
@@ -132,7 +132,9 @@ For long tables, the header row can be made to "stick" in place as the user scro
132
132
 
133
133
  ## Sortable Column Buttons [d2l-table-col-sort-button]
134
134
 
135
- When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used to provide an interactive sort button as well as arrows to indicate the ascending/descending sort direction.
135
+ When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used to provide an interactive sort button as well as arrows to indicate the ascending/descending sort direction. This is meant to be used within a `d2l-table-wrapper`.
136
+
137
+ Note that the example below hides much of the implementation. See the code in [Multi-Faceted Sort Button](#multi-faceted-sort-button) for a more detailed implementation example.
136
138
 
137
139
  <!-- docs: demo -->
138
140
  ```html
@@ -210,15 +212,17 @@ When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used t
210
212
  ```
211
213
 
212
214
  ```html
213
- <table class="d2l-table">
214
- <thead>
215
- <tr>
216
- <th><d2l-table-col-sort-button>Ascending</d2l-table-col-sort-button></th>
217
- <th><d2l-table-col-sort-button desc>Descending</d2l-table-col-sort-button></th>
218
- <th><d2l-table-col-sort-button nosort>Not Sorted</d2l-table-col-sort-button></th>
219
- </tr>
220
- </thead>
221
- </table>
215
+ <d2l-table-wrapper>
216
+ <table class="d2l-table">
217
+ <thead>
218
+ <tr>
219
+ <th><d2l-table-col-sort-button>Ascending</d2l-table-col-sort-button></th>
220
+ <th><d2l-table-col-sort-button desc>Descending</d2l-table-col-sort-button></th>
221
+ <th><d2l-table-col-sort-button nosort>Not Sorted</d2l-table-col-sort-button></th>
222
+ </tr>
223
+ </thead>
224
+ </table>
225
+ </d2l-table-wrapper>
222
226
  ```
223
227
 
224
228
  ### Properties
@@ -228,7 +232,134 @@ When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used t
228
232
  | `desc` | boolean | Whether sort direction is descending | false |
229
233
  | `nosort` | boolean | Column is not currently sorted. Hides the ascending/descending sort icon. | false |
230
234
  | `position` | string | Position of the button content. Accepted values are 'start', 'center', and 'end'. | 'start' |
231
- | `source-type` | string | The type of data in the column. Used to set the title. Accepted values are 'words', 'numbers', and 'dates'. | 'unknown' |
235
+ | `source-type` | string | The type of data in the column. Used to set the title. Accepted values are 'words', 'numbers', and 'dates'. This is only applicable to cases that are not using the multi-faceted dropdown. | 'unknown' |
236
+
237
+ ### Slots
238
+ | Name | Description |
239
+ |---|---|
240
+ | `Default` | Column header text |
241
+ | `items` | Multi-facted sort items. Generally assigned to the `slot` attribute on a nested `d2l-table-col-sort-button-item`. |
242
+
243
+ ### Slotted Item [d2l-table-col-sort-button-item]
244
+
245
+ This is a radio menu item to be used within the `d2l-table-col-sort-button` component for a [multi-faceted sort](#multi-faceted-sort-button).
246
+
247
+ <!-- docs: demo code properties autoSize:false align:start name:d2l-table-col-sort-button-item -->
248
+ ```html
249
+ <script type="module">
250
+ import '@brightspace-ui/core/components/table/table-col-sort-button.js';
251
+ import '@brightspace-ui/core/components/table/table-col-sort-button-item.js';
252
+ </script>
253
+ <!-- docs: start hidden content -->
254
+ <style>
255
+ d2l-table-col-sort-button {
256
+ --d2l-table-cell-padding: 10px;
257
+ }
258
+ </style>
259
+ <!-- docs: end hidden content -->
260
+ <d2l-table-col-sort-button desc>
261
+ Items
262
+ <d2l-table-col-sort-button-item text="Item 1" slot="items" value="item1"></d2l-table-col-sort-button-item>
263
+ <d2l-table-col-sort-button-item text="Item 2" slot="items" value="item2"></d2l-table-col-sort-button-item>
264
+ </d2l-table-col-sort-button>
265
+ ```
266
+
267
+ ### Multi-Faceted Sort Button
268
+
269
+ When a single column is responsible for sorting in multiple facets (e.g., first name and last name), it is recommended to use the dropdown menu approach by slotting `d2l-table-col-sort-button-item` components within the `d2l-table-col-sort-button`. Please note that the consumer is responsible for all sort logic, including when `desc` and `nosort` are set on `d2l-table-col-sort-button`.
270
+
271
+ **WARNING**: Do NOT use this if the table is using `sticky-headers` AND multiple header rows. It is not currently supported. In that siuation, continue to put multiple `d2l-table-col-sort-button` components in the same column.
272
+
273
+ <!-- docs: demo code display:block -->
274
+ ```html
275
+ <script type="module">
276
+ import '@brightspace-ui/core/components/table/table-col-sort-button.js';
277
+ import '@brightspace-ui/core/components/table/table-col-sort-button-item.js';
278
+ import { html, LitElement } from 'lit';
279
+ import { tableStyles } from '@brightspace-ui/core/components/table/table-wrapper.js';
280
+ const data = () => [
281
+ { firstname: 'John', lastname: 'Smith', grade: 85 },
282
+ { firstname: 'Emily', lastname: 'Jones', grade: 92 },
283
+ { firstname: 'Michael', lastname: 'Davis', grade: 78 },
284
+ { firstname: 'Sarah', lastname: 'Brown', grade: 90 },
285
+ { firstname: 'David', lastname: 'Wilson', grade: 88 },
286
+ { firstname: 'Jessica', lastname: 'Taylor', grade: 95 },
287
+ { firstname: 'Christopher', lastname: 'Martinez', grade: 83 }
288
+ ];
289
+ class MyComplexSortableTableElem extends LitElement {
290
+ static get properties() {
291
+ return {
292
+ _desc: { state: true },
293
+ _field: { state: true }
294
+ };
295
+ }
296
+ static get styles() {
297
+ return tableStyles;
298
+ }
299
+ constructor() {
300
+ super();
301
+ this._data = data();
302
+ this._desc = false;
303
+ }
304
+ render() {
305
+ const rowData = this._field ? this._data.sort((a, b) => {
306
+ if (this._desc) {
307
+ if (a[this._field] > b[this._field]) return -1;
308
+ if (a[this._field] < b[this._field]) return 1;
309
+ } else {
310
+ if (a[this._field] < b[this._field]) return -1;
311
+ if (a[this._field] > b[this._field]) return 1;
312
+ }
313
+ return 0;
314
+ }) : this._data;
315
+ const rows = rowData.map(i => {
316
+ return html`<tr>
317
+ <td>${i.firstname} ${i.lastname}</td>
318
+ <td>${i.grade}</td>
319
+ </tr>
320
+ `;
321
+ });
322
+ return html`
323
+ <d2l-table-wrapper>
324
+ <table class="d2l-table">
325
+ <thead>
326
+ <tr>
327
+ <th>
328
+ <d2l-table-col-sort-button ?desc="${this._desc}" ?nosort="${this._field !== 'firstname' && this._field !== 'lastname'}">
329
+ Learner
330
+ <d2l-table-col-sort-button-item slot="items" text="First Name, A to Z" data-field="firstname" @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="1"></d2l-table-col-sort-button-item>
331
+ <d2l-table-col-sort-button-item slot="items" text="First Name, Z to A" data-field="firstname" data-desc @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="2"></d2l-table-col-sort-button-item>
332
+ <d2l-table-col-sort-button-item slot="items" text="Last Name, A to Z" data-field="lastname" @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="3"></d2l-table-col-sort-button-item>
333
+ <d2l-table-col-sort-button-item slot="items" text="Last Name, Z to A" data-field="lastname" data-desc @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="4"></d2l-table-col-sort-button-item>
334
+ </d2l-table-col-sort-button>
335
+ </th>
336
+ <th>
337
+ <d2l-table-col-sort-button ?desc="${this._desc}" data-field="grade" @click="${this._handleSort}" ?nosort="${this._field !== 'grade'}">Grade</d2l-table-col-sort-button>
338
+ </th>
339
+ </tr>
340
+ </thead>
341
+ <tbody>
342
+ ${rows}
343
+ </tbody>
344
+ </table>
345
+ </d2l-table-wrapper>
346
+ `;
347
+ }
348
+ _handleSort(e) {
349
+ const field = e.target.getAttribute('data-field');
350
+ const desc = e.target.hasAttribute('desc');
351
+ this._desc = field === this._field ? !desc : false;
352
+ this._field = field;
353
+ }
354
+ _handleSortComplex(e) {
355
+ this._field = e.target.getAttribute('data-field');
356
+ this._desc = e.target.hasAttribute('data-desc');
357
+ }
358
+ }
359
+ customElements.define('d2l-my-complex-sortable-table-elem', MyComplexSortableTableElem);
360
+ </script>
361
+ <d2l-my-complex-sortable-table-elem></d2l-my-complex-sortable-table-elem>
362
+ ```
232
363
 
233
364
  ## Selection
234
365
 
@@ -6,6 +6,9 @@ import { RtlMixin } from '../../mixins/rtl/rtl-mixin.js';
6
6
 
7
7
  /**
8
8
  * A radio menu item to be used within the d2l-table-col-sort-button component for a multi-faceted sort.
9
+ * @fires d2l-menu-item-change - Internal event
10
+ * @fires d2l-menu-item-select - Internal event
11
+ * @fires d2l-menu-item-visibility-change - Internal event
9
12
  */
10
13
  class TableColSortButtonItem extends RtlMixin(MenuItemRadioMixin(LitElement)) {
11
14
 
@@ -9282,6 +9282,11 @@
9282
9282
  "description": "Total number of items. If not specified, features like select-all-pages will be disabled.",
9283
9283
  "type": "number"
9284
9284
  },
9285
+ {
9286
+ "name": "selectionNoInputArrowKeyBehaviour",
9287
+ "type": "boolean",
9288
+ "default": "false"
9289
+ },
9285
9290
  {
9286
9291
  "name": "selectionSingle",
9287
9292
  "attribute": "selection-single",
@@ -10617,6 +10622,11 @@
10617
10622
  }
10618
10623
  ],
10619
10624
  "properties": [
10625
+ {
10626
+ "name": "selectionNoInputArrowKeyBehaviour",
10627
+ "type": "boolean",
10628
+ "default": "false"
10629
+ },
10620
10630
  {
10621
10631
  "name": "selectionSingle",
10622
10632
  "attribute": "selection-single",
@@ -10662,6 +10672,11 @@
10662
10672
  }
10663
10673
  ],
10664
10674
  "properties": [
10675
+ {
10676
+ "name": "selectionNoInputArrowKeyBehaviour",
10677
+ "type": "boolean",
10678
+ "default": "false"
10679
+ },
10665
10680
  {
10666
10681
  "name": "selectionSingle",
10667
10682
  "attribute": "selection-single",
@@ -11314,6 +11329,11 @@
11314
11329
  }
11315
11330
  ],
11316
11331
  "properties": [
11332
+ {
11333
+ "name": "selectionNoInputArrowKeyBehaviour",
11334
+ "type": "boolean",
11335
+ "default": "false"
11336
+ },
11317
11337
  {
11318
11338
  "name": "selectionSingle",
11319
11339
  "attribute": "selection-single",
@@ -11413,6 +11433,11 @@
11413
11433
  }
11414
11434
  ],
11415
11435
  "properties": [
11436
+ {
11437
+ "name": "selectionNoInputArrowKeyBehaviour",
11438
+ "type": "boolean",
11439
+ "default": "false"
11440
+ },
11416
11441
  {
11417
11442
  "name": "selectionSingle",
11418
11443
  "attribute": "selection-single",
@@ -11997,6 +12022,11 @@
11997
12022
  "description": "Total number of items. If not specified, features like select-all-pages will be disabled.",
11998
12023
  "type": "number"
11999
12024
  },
12025
+ {
12026
+ "name": "selectionNoInputArrowKeyBehaviour",
12027
+ "type": "boolean",
12028
+ "default": "false"
12029
+ },
12000
12030
  {
12001
12031
  "name": "selectionSingle",
12002
12032
  "attribute": "selection-single",
@@ -12088,21 +12118,21 @@
12088
12118
  }
12089
12119
  ],
12090
12120
  "events": [
12091
- {
12092
- "name": "d2l-table-col-sort-button-item-change",
12093
- "description": "Dispatched when the selected multi-faceted sort option changes"
12094
- },
12095
12121
  {
12096
12122
  "name": "d2l-menu-item-change",
12097
- "description": "Dispatched when the selected menu item changes"
12123
+ "description": "Internal event"
12098
12124
  },
12099
12125
  {
12100
12126
  "name": "d2l-menu-item-select",
12101
- "description": "Dispatched when the menu item is selected"
12127
+ "description": "Internal event"
12102
12128
  },
12103
12129
  {
12104
12130
  "name": "d2l-menu-item-visibility-change",
12105
- "description": "Dispatched when the visibility of the menu item changes"
12131
+ "description": "Internal event"
12132
+ },
12133
+ {
12134
+ "name": "d2l-table-col-sort-button-item-change",
12135
+ "description": "Dispatched when the selected multi-faceted sort option changes"
12106
12136
  }
12107
12137
  ]
12108
12138
  },
@@ -12353,6 +12383,11 @@
12353
12383
  "description": "Total number of items. If not specified, features like select-all-pages will be disabled.",
12354
12384
  "type": "number"
12355
12385
  },
12386
+ {
12387
+ "name": "selectionNoInputArrowKeyBehaviour",
12388
+ "type": "boolean",
12389
+ "default": "false"
12390
+ },
12356
12391
  {
12357
12392
  "name": "selectionSingle",
12358
12393
  "attribute": "selection-single",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.5.0",
3
+ "version": "3.5.2",
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",