Skip to content

Commit 7c91a50

Browse files
committed
sorting works with minimized changeset
1 parent ac753da commit 7c91a50

File tree

6 files changed

+32
-34
lines changed

6 files changed

+32
-34
lines changed

packages/components/src/components/hds/table/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{{#if @columns}}
1515
<Hds::Table::Tr
1616
@sortOrder={{if (eq this.sortBy @selectedItemKey) this.sortOrder}}
17+
@onClickSort={{fn this.setSortBy @selectedItemKey}}
1718
@selectionScope="col"
1819
@isSelectable={{@isSelectable}}
1920
@onSelectionChange={{this.onSelectionAllChange}}
@@ -79,7 +80,6 @@
7980
"hds/table/tr"
8081
selectionScope="row"
8182
isSelectable=@isSelectable
82-
onClickSort=(fn this.setSortBy @selectedItemKey)
8383
onSelectionChange=this.onSelectionRowChange
8484
didInsert=this.didInsertRowCheckbox
8585
willDestroy=this.willDestroyRowCheckbox

packages/components/src/components/hds/table/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export const DEFAULT_VALIGN = HdsTableVerticalAlignmentValues.Top;
4343

4444
export interface HdsTableArgs {
4545
Args: {
46+
selectedItemKey?: string;
47+
// new above here
4648
align?: HdsTableHorizontalAlignment;
4749
caption?: string;
4850
columns?: HdsTableColumn[];
@@ -52,7 +54,6 @@ export interface HdsTableArgs {
5254
isSelectable?: boolean;
5355
isStriped?: boolean;
5456
model: HdsTableModel;
55-
selectedItemKey?: string;
5657
onSelectionChange?: (selection: HdsTableOnSelectionChangeArgs) => void;
5758
onSort?: (sortBy: string, sortOrder: HdsTableThSortOrder) => void;
5859
selectionAriaLabelSuffix?: string;

packages/components/src/components/hds/table/th-button-sort.ts

-27
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,9 @@ export interface HdsTableThButtonSortArgs {
2727
const NOOP = () => {};
2828

2929
export default class HdsTableThButtonSort extends Component<HdsTableThButtonSortArgs> {
30-
/**
31-
* Generates a unique ID for the (hidden) "label prefix/suffix" <span> elements
32-
*
33-
* @param prefixLabelId/suffixLabelId
34-
*/
3530
prefixLabelId = 'prefix-' + guidFor(this);
3631
suffixLabelId = 'suffix-' + guidFor(this);
3732

38-
/**
39-
* @param icon
40-
* @type {HdsTableThSortOrderIcons}
41-
* @private
42-
* @default swap-vertical
43-
* @description Determines which icon to use based on the sort order defined
44-
*/
4533
get icon(): HdsTableThSortOrderIcons {
4634
switch (this.args.sortOrder) {
4735
case HdsTableThSortOrderValues.Asc:
@@ -53,22 +41,12 @@ export default class HdsTableThButtonSort extends Component<HdsTableThButtonSort
5341
}
5442
}
5543

56-
/**
57-
* @param sortOrderLabel
58-
* @default 'ascending'
59-
* @description Determines the label (suffix) to use in the `aria-labelledby` attribute of the button, used to indicate what will happen if the user clicks on the button
60-
*/
6144
get sortOrderLabel(): HdsTableThSortOrderLabels {
6245
return this.args.sortOrder === HdsTableThSortOrderValues.Asc
6346
? HdsTableThSortOrderLabelValues.Desc
6447
: HdsTableThSortOrderLabelValues.Asc;
6548
}
6649

67-
/**
68-
* @param onClick
69-
* @type {function}
70-
* @default () => {}
71-
*/
7250
get onClick(): () => void {
7351
const { onClick } = this.args;
7452

@@ -79,11 +57,6 @@ export default class HdsTableThButtonSort extends Component<HdsTableThButtonSort
7957
}
8058
}
8159

82-
/**
83-
* Get the class names to apply to the component.
84-
* @method classNames
85-
* @return {string} The "class" attribute to apply to the component.
86-
*/
8760
get classNames(): string {
8861
const classes = ['hds-table__th-button', 'hds-table__th-button--sort'];
8962

packages/components/src/components/hds/table/th-selectable.ts

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ export interface HdsTableThSelectableArgs {
3838
export default class HdsTableThSelectable extends Component<HdsTableThSelectableArgs> {
3939
@tracked isSelected = this.args.isSelected;
4040

41-
/**
42-
* Generate a unique ID for the Checkbox
43-
* @return {string}
44-
*/
4541
checkboxId = 'checkbox-' + guidFor(this);
4642

4743
get ariaLabel(): string {

packages/components/src/components/hds/table/tr.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SPDX-License-Identifier: MPL-2.0
44
}}
55

6-
<tr class="hds-table__tr" ...attributes>
6+
<tr class="hds-table__tr" {{did-insert this.didInsert}} ...attributes>
77
{{#if @isSelectable}}
88
<Hds::Table::ThSelectable
99
@isHeaderRow={{this.isHeaderRow}}

showcase/app/templates/components/table.hbs

+28
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@
99

1010
<section data-test-percy>
1111

12+
<Shw::Text::H2>🎉 NEW! - Sort by Selected</Shw::Text::H2>
13+
14+
<Shw::Text::H4 @tag="h3">Internal Sorting</Shw::Text::H4>
15+
16+
<Hds::Table
17+
@isSelectable={{true}}
18+
@selectedItemKey="isSelected"
19+
@onSelectionChange={{this.onSelectionChangeLogArguments}}
20+
@model={{this.model.selectableData}}
21+
@columns={{array
22+
(hash key="lorem" label="Row #")
23+
(hash key="ipsum" label="Ipsum")
24+
(hash key="dolor" label="Dolor")
25+
}}
26+
>
27+
<:body as |B|>
28+
<B.Tr
29+
@selectionKey={{B.data.id}}
30+
@isSelected={{B.data.isSelected}}
31+
@selectionAriaLabelSuffix="row #{{B.data.lorem}}"
32+
>
33+
<B.Td>{{B.data.lorem}}</B.Td>
34+
<B.Td>{{B.data.ipsum}}</B.Td>
35+
<B.Td>{{B.data.dolor}}</B.Td>
36+
</B.Tr>
37+
</:body>
38+
</Hds::Table>
39+
1240
<Shw::Text::H2>Data model</Shw::Text::H2>
1341

1442
<Shw::Text::H4 @tag="h3">Table with model</Shw::Text::H4>

0 commit comments

Comments
 (0)