@brightspace-ui/core 3.213.1 → 3.214.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.
@@ -366,19 +366,26 @@ When a single column is responsible for sorting in multiple facets (e.g., first
366
366
 
367
367
  ## Selection
368
368
 
369
- If your table supports row selection, apply the `selected` attribute to `<tr>` row elements which are actively selected.
369
+ Table rows can support both single- and multi-select by leveraging [Selection](../../components/selection/) components.
370
+
371
+ To enable selection, add `d2l-selection-input` components in the selection column, and a `d2l-selection-select-all` component in the the column's header cell. Apply the `selected` attribute to `<tr>` row elements which are actively selected.
372
+
373
+ **Important:** Single selection tables won't need the Select All component in the header, so be sure to add an `aria-label` for screen reader users.
370
374
 
371
375
  <!-- docs: demo -->
372
376
  ```html
373
377
  <script type="module">
378
+ import '@brightspace-ui/core/components/selection/selection-input.js';
379
+ import '@brightspace-ui/core/components/selection/selection-select-all.js';
374
380
  import { html, LitElement } from 'lit';
375
381
  import { tableStyles } from '@brightspace-ui/core/components/table/table-wrapper.js';
376
382
 
377
- class MySelectableTableElem extends LitElement {
383
+ class SampleTableWithSelectionInputs extends LitElement {
378
384
 
379
385
  static get properties() {
380
386
  return {
381
- _checked: { type: Boolean }
387
+ selectionSingle: { type: Boolean, attribute: 'selection-single' },
388
+ _data: { state: true }
382
389
  }
383
390
  }
384
391
 
@@ -388,45 +395,83 @@ If your table supports row selection, apply the `selected` attribute to `<tr>` r
388
395
 
389
396
  constructor() {
390
397
  super();
391
- this._checked = true;
398
+ this.selectionSingle = false;
399
+ this._data = [{ name: 'John Smith', checked: true }, { name: 'Emily Jones', checked: false }];
392
400
  }
393
401
 
394
402
  render() {
395
403
  return html`
396
- <d2l-table-wrapper>
404
+ <d2l-table-wrapper ?selection-single="${this.selectionSingle}">
397
405
  <table class="d2l-table">
398
406
  <thead>
399
407
  <tr>
400
- <th>Column A</th>
401
- <th>Column B</th>
408
+ ${!this.selectionSingle ? html`<th><d2l-selection-select-all></d2l-selection-select-all></th>` : html`<th aria-label="Selection column"></th>`}
409
+ <th>Learner</th>
402
410
  </tr>
403
411
  </thead>
404
412
  <tbody>
405
- <tr ?selected="${this._checked}">
406
- <td><input type="checkbox" ?checked="${this._checked}" @click="${this._selectRow}"></td>
407
- <td>this row is ${!this._checked ? 'not' : ''} selected</td>
408
- </tr>
413
+ ${this._data.map((rowData, i) => html`
414
+ <tr ?selected="${rowData.checked}">
415
+ <td>
416
+ <d2l-selection-input key="${i}" label="${rowData.name}" ?selected="${rowData.checked}" @d2l-selection-change="${this._selectRow}"></d2l-selection-input>
417
+ </td>
418
+ <td>${rowData.name}</td>
419
+ </tr>
420
+ `)}
409
421
  </tbody>
410
422
  </table>
411
423
  </d2l-table-wrapper>
412
424
  `;
413
425
  }
414
426
 
415
- _selectRow() {
416
- this._checked = !this._checked;
427
+ _selectRow(e) {
428
+ const key = e.target.key;
429
+ this._data[key].checked = e.target.selected;
430
+ this.requestUpdate();
417
431
  }
418
432
 
419
433
  }
420
- customElements.define('d2l-my-selectable-table-elem', MySelectableTableElem);
434
+ customElements.define('d2l-sample-table-with-selection-inputs', SampleTableWithSelectionInputs);
421
435
  </script>
422
- <d2l-my-selectable-table-elem></d2l-my-selectable-table-elem>
436
+ <d2l-sample-table-with-selection-inputs></d2l-sample-table-with-selection-inputs>
437
+ <d2l-sample-table-with-selection-inputs selection-single></d2l-sample-table-with-selection-inputs>
423
438
  ```
424
439
 
425
440
  ```html
426
- <tr selected>
427
- <td><input type="checkbox" checked></td>
428
- <td>this row is selected</td>
429
- </tr>
441
+ <d2l-table-wrapper>
442
+ <table class="d2l-table">
443
+ <thead>
444
+ <tr>
445
+ <th><d2l-selection-select-all></d2l-selection-select-all></th>
446
+ <th>Learner</th>
447
+ </tr>
448
+ </thead>
449
+ <tbody>
450
+ <tr selected>
451
+ <td><d2l-selection-input key="1" label="John Smith" selected></d2l-selection-input></td>
452
+ <td>John Smith</td>
453
+ </tr>
454
+ <tr>
455
+ <td><d2l-selection-input key="2" label="Emily Jones"></d2l-selection-input></td>
456
+ <td>Emily Jones</td>
457
+ </tr>
458
+ </tbody>
459
+ </table>
460
+ </d2l-table-wrapper>
461
+ ```
462
+
463
+ ```html
464
+ <d2l-table-wrapper selection-single>
465
+ <table class="d2l-table">
466
+ <thead>
467
+ <tr>
468
+ <th aria-label="Selection column"></th>
469
+ <th>Learner</th>
470
+ </tr>
471
+ </thead>
472
+ ...
473
+ </table>
474
+ </d2l-table-wrapper>
430
475
  ```
431
476
 
432
477
  ## Pageable Tables
@@ -462,8 +507,8 @@ The `d2l-table-controls` component can be placed in the `d2l-table-wrapper`'s `c
462
507
  constructor() {
463
508
  super();
464
509
  this._data = {
465
- a: { checked: true },
466
- b: { checked: false },
510
+ a: { checked: false, notes: 'Scroll down to see sticky header behaviour.' },
511
+ b: { checked: false, notes: 'Reduce the width to see the control actions chomp.' },
467
512
  };
468
513
  }
469
514
 
@@ -471,23 +516,25 @@ The `d2l-table-controls` component can be placed in the `d2l-table-wrapper`'s `c
471
516
  return html`
472
517
  <d2l-table-wrapper>
473
518
  <d2l-table-controls slot="controls">
519
+ <d2l-selection-action icon="tier1:edit" text="Edit" requires-selection></d2l-selection-action>
474
520
  <d2l-selection-action icon="tier1:delete" text="Delete" requires-selection></d2l-selection-action>
475
521
  <d2l-selection-action icon="tier1:gear" text="Settings"></d2l-selection-action>
522
+ <d2l-selection-action icon="tier1:help" text="Help"></d2l-selection-action>
476
523
  </d2l-table-controls>
477
524
  <table class="d2l-table">
478
525
  <thead>
479
526
  <tr>
480
- <th><d2l-selection-select-all></d2l-selection-select-all></th>
481
- <th>Column B</th>
527
+ <th style="width: 1px;"><d2l-selection-select-all></d2l-selection-select-all></th>
528
+ <th>Notes</th>
482
529
  </tr>
483
530
  </thead>
484
531
  <tbody>
485
532
  ${Object.keys(this._data).map((key, i) => html`
486
- <tr>
533
+ <tr ?selected="${this._data[key].checked}">
487
534
  <td>
488
535
  <d2l-selection-input key="${key}" label="${key}" ?selected="${this._data[key].checked}" @d2l-selection-change="${this._selectRow}"></d2l-selection-input>
489
536
  </td>
490
- <td>this row is ${!this._data[key].checked ? 'not' : ''} selected</td>
537
+ <td>${this._data[key].notes}</td>
491
538
  </tr>
492
539
  `)}
493
540
  </tbody>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.213.1",
3
+ "version": "3.214.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",