Skip to content

Commit 4db2eb7

Browse files
authored
feat(list-item): Add dragSelected property and calciteListItemDragHandleChange event (#8524)
**Related Issue:** #8523 ## Summary - Depends on #8484 - Add dragSelected property - Add calciteListItemDragHandleChange event - Add test
1 parent 11654b9 commit 4db2eb7

File tree

3 files changed

+78
-26
lines changed

3 files changed

+78
-26
lines changed

packages/calcite-components/src/components.d.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export namespace Components {
313313
}
314314
interface CalciteActionBar {
315315
/**
316-
* Specifies the accessible label for the last action-group.
316+
* Specifies the accessible label for the last `calcite-action-group`.
317317
*/
318318
"actionsEndGroupLabel": string;
319319
/**
@@ -325,7 +325,7 @@ export namespace Components {
325325
*/
326326
"expanded": boolean;
327327
/**
328-
* The layout direction of the actions.
328+
* Specifies the layout direction of the actions.
329329
*/
330330
"layout": Extract<"horizontal" | "vertical", Layout>;
331331
/**
@@ -367,7 +367,7 @@ export namespace Components {
367367
*/
368368
"expanded": boolean;
369369
/**
370-
* Specifies the label of the component. Required for accessibility.
370+
* Accessible name for the component.
371371
*/
372372
"label": string;
373373
/**
@@ -440,7 +440,7 @@ export namespace Components {
440440
}
441441
interface CalciteActionPad {
442442
/**
443-
* Specifies the accessible label for the last action-group.
443+
* Specifies the accessible label for the last `calcite-action-group`.
444444
*/
445445
"actionsEndGroupLabel": string;
446446
/**
@@ -478,11 +478,11 @@ export namespace Components {
478478
}
479479
interface CalciteAlert {
480480
/**
481-
* When `true`, the component closes automatically (recommended for passive, non-blocking alerts).
481+
* When `true`, the component closes automatically. Recommended for passive, non-blocking alerts.
482482
*/
483483
"autoClose": boolean;
484484
/**
485-
* Specifies the duration before the component automatically closes (only use with `autoClose`).
485+
* Specifies the duration before the component automatically closes - only use with `autoClose`.
486486
*/
487487
"autoCloseDuration": AlertDuration;
488488
/**
@@ -494,7 +494,7 @@ export namespace Components {
494494
*/
495495
"iconFlipRtl": boolean;
496496
/**
497-
* Specifies the kind of the component (will apply to top border and icon).
497+
* Specifies the kind of the component, which will apply to top border and icon.
498498
*/
499499
"kind": Extract<
500500
"brand" | "danger" | "info" | "success" | "warning",
@@ -521,15 +521,15 @@ export namespace Components {
521521
*/
522522
"open": boolean;
523523
/**
524-
* Specifies the placement of the component
524+
* Specifies the placement of the component.
525525
*/
526526
"placement": MenuPlacement;
527527
/**
528528
* Specifies the size of the component.
529529
*/
530530
"scale": Scale;
531531
/**
532-
* Sets focus on the component's "close" button (the first focusable item).
532+
* Sets focus on the component's "close" button, the first focusable item.
533533
*/
534534
"setFocus": () => Promise<void>;
535535
/**
@@ -1768,10 +1768,6 @@ export namespace Components {
17681768
"min": number;
17691769
}
17701770
interface CalciteHandle {
1771-
/**
1772-
* When `true`, disables unselecting the component when blurred.
1773-
*/
1774-
"blurUnselectDisabled": boolean;
17751771
/**
17761772
* When `true`, disables unselecting the component when blurred.
17771773
*/
@@ -2845,6 +2841,10 @@ export namespace Components {
28452841
* When `true`, the component displays a draggable button.
28462842
*/
28472843
"dragHandle": boolean;
2844+
/**
2845+
* When `true`, the component's drag handle is selected.
2846+
*/
2847+
"dragSelected": boolean;
28482848
/**
28492849
* The label text of the component. Displays above the description text.
28502850
*/
@@ -6379,6 +6379,7 @@ declare global {
63796379
interface HTMLCalciteListItemElementEventMap {
63806380
"calciteListItemSelect": void;
63816381
"calciteListItemClose": void;
6382+
"calciteListItemDragHandleChange": void;
63826383
"calciteListItemToggle": void;
63836384
"calciteInternalListItemSelect": void;
63846385
"calciteInternalListItemSelectMultiple": {
@@ -7525,7 +7526,7 @@ declare namespace LocalJSX {
75257526
}
75267527
interface CalciteActionBar {
75277528
/**
7528-
* Specifies the accessible label for the last action-group.
7529+
* Specifies the accessible label for the last `calcite-action-group`.
75297530
*/
75307531
"actionsEndGroupLabel"?: string;
75317532
/**
@@ -7537,7 +7538,7 @@ declare namespace LocalJSX {
75377538
*/
75387539
"expanded"?: boolean;
75397540
/**
7540-
* The layout direction of the actions.
7541+
* Specifies the layout direction of the actions.
75417542
*/
75427543
"layout"?: Extract<"horizontal" | "vertical", Layout>;
75437544
/**
@@ -7575,7 +7576,7 @@ declare namespace LocalJSX {
75757576
*/
75767577
"expanded"?: boolean;
75777578
/**
7578-
* Specifies the label of the component. Required for accessibility.
7579+
* Accessible name for the component.
75797580
*/
75807581
"label"?: string;
75817582
/**
@@ -7644,7 +7645,7 @@ declare namespace LocalJSX {
76447645
}
76457646
interface CalciteActionPad {
76467647
/**
7647-
* Specifies the accessible label for the last action-group.
7648+
* Specifies the accessible label for the last `calcite-action-group`.
76487649
*/
76497650
"actionsEndGroupLabel"?: string;
76507651
/**
@@ -7682,11 +7683,11 @@ declare namespace LocalJSX {
76827683
}
76837684
interface CalciteAlert {
76847685
/**
7685-
* When `true`, the component closes automatically (recommended for passive, non-blocking alerts).
7686+
* When `true`, the component closes automatically. Recommended for passive, non-blocking alerts.
76867687
*/
76877688
"autoClose"?: boolean;
76887689
/**
7689-
* Specifies the duration before the component automatically closes (only use with `autoClose`).
7690+
* Specifies the duration before the component automatically closes - only use with `autoClose`.
76907691
*/
76917692
"autoCloseDuration"?: AlertDuration;
76927693
/**
@@ -7698,7 +7699,7 @@ declare namespace LocalJSX {
76987699
*/
76997700
"iconFlipRtl"?: boolean;
77007701
/**
7701-
* Specifies the kind of the component (will apply to top border and icon).
7702+
* Specifies the kind of the component, which will apply to top border and icon.
77027703
*/
77037704
"kind"?: Extract<
77047705
"brand" | "danger" | "info" | "success" | "warning",
@@ -7749,7 +7750,7 @@ declare namespace LocalJSX {
77497750
*/
77507751
"open"?: boolean;
77517752
/**
7752-
* Specifies the placement of the component
7753+
* Specifies the placement of the component.
77537754
*/
77547755
"placement"?: MenuPlacement;
77557756
/**
@@ -9074,10 +9075,6 @@ declare namespace LocalJSX {
90749075
"min": number;
90759076
}
90769077
interface CalciteHandle {
9077-
/**
9078-
* When `true`, disables unselecting the component when blurred.
9079-
*/
9080-
"blurUnselectDisabled"?: boolean;
90819078
/**
90829079
* When `true`, disables unselecting the component when blurred.
90839080
*/
@@ -10217,6 +10214,10 @@ declare namespace LocalJSX {
1021710214
* When `true`, the component displays a draggable button.
1021810215
*/
1021910216
"dragHandle"?: boolean;
10217+
/**
10218+
* When `true`, the component's drag handle is selected.
10219+
*/
10220+
"dragSelected"?: boolean;
1022010221
/**
1022110222
* The label text of the component. Displays above the description text.
1022210223
*/
@@ -10244,6 +10245,10 @@ declare namespace LocalJSX {
1024410245
* Fires when the close button is clicked.
1024510246
*/
1024610247
"onCalciteListItemClose"?: (event: CalciteListItemCustomEvent<void>) => void;
10248+
/**
10249+
* Fires when the drag handle is selected.
10250+
*/
10251+
"onCalciteListItemDragHandleChange"?: (event: CalciteListItemCustomEvent<void>) => void;
1024710252
/**
1024810253
* Emits when the item's content is selected.
1024910254
*/

packages/calcite-components/src/components/list-item/list-item.e2e.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ describe("calcite-list-item", () => {
4848
propertyName: "dragHandle",
4949
defaultValue: false,
5050
},
51+
{
52+
propertyName: "dragSelected",
53+
defaultValue: false,
54+
},
5155
]);
5256
});
5357

@@ -300,4 +304,29 @@ describe("calcite-list-item", () => {
300304
expect(await listItem.getProperty("open")).toBe(false);
301305
expect(calciteListItemToggle).toHaveReceivedEventTimes(2);
302306
});
307+
308+
it("should fire calciteListItemDragHandleChange event when drag handle is clicked", async () => {
309+
const page = await newE2EPage({
310+
html: html`<calcite-list-item drag-handle></calcite-list-item>`,
311+
});
312+
313+
const listItem = await page.find("calcite-list-item");
314+
const calciteListItemDragHandleChange = await page.spyOnEvent("calciteListItemDragHandleChange", "window");
315+
316+
expect(await listItem.getProperty("dragSelected")).toBe(false);
317+
318+
const dragHandle = await page.find(`calcite-list-item >>> calcite-handle`);
319+
await dragHandle.callMethod("setFocus");
320+
await page.waitForChanges();
321+
322+
await dragHandle.press("Space");
323+
await page.waitForChanges();
324+
expect(await listItem.getProperty("dragSelected")).toBe(true);
325+
expect(calciteListItemDragHandleChange).toHaveReceivedEventTimes(1);
326+
327+
await dragHandle.press("Space");
328+
await page.waitForChanges();
329+
expect(await listItem.getProperty("dragSelected")).toBe(false);
330+
expect(calciteListItemDragHandleChange).toHaveReceivedEventTimes(2);
331+
});
303332
});

packages/calcite-components/src/components/list-item/list-item.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ export class ListItem
137137
*/
138138
@Prop() dragHandle = false;
139139

140+
/**
141+
* When `true`, the component's drag handle is selected.
142+
*/
143+
@Prop({ mutable: true, reflect: true }) dragSelected = false;
144+
140145
/**
141146
* The label text of the component. Displays above the description text.
142147
*/
@@ -233,6 +238,11 @@ export class ListItem
233238
*/
234239
@Event({ cancelable: false }) calciteListItemClose: EventEmitter<void>;
235240

241+
/**
242+
* Fires when the drag handle is selected.
243+
*/
244+
@Event({ cancelable: false }) calciteListItemDragHandleChange: EventEmitter<void>;
245+
236246
/**
237247
* Fires when the open button is clicked.
238248
*/
@@ -429,7 +439,7 @@ export class ListItem
429439
}
430440

431441
renderDragHandle(): VNode {
432-
const { label, dragHandle, dragDisabled, setPosition, setSize } = this;
442+
const { label, dragHandle, dragSelected, dragDisabled, setPosition, setSize } = this;
433443

434444
return dragHandle ? (
435445
<td
@@ -444,6 +454,8 @@ export class ListItem
444454
<calcite-handle
445455
disabled={dragDisabled}
446456
label={label}
457+
onCalciteHandleChange={this.dragHandleSelectedChangeHandler}
458+
selected={dragSelected}
447459
setPosition={setPosition}
448460
setSize={setSize}
449461
/>
@@ -690,6 +702,12 @@ export class ListItem
690702
//
691703
// --------------------------------------------------------------------------
692704

705+
private dragHandleSelectedChangeHandler = (event: CustomEvent): void => {
706+
this.dragSelected = (event.target as HTMLCalciteHandleElement).selected;
707+
this.calciteListItemDragHandleChange.emit();
708+
event.stopPropagation();
709+
};
710+
693711
private emitInternalListItemActive = (): void => {
694712
this.calciteInternalListItemActive.emit();
695713
};

0 commit comments

Comments
 (0)