Skip to content

Commit

Permalink
feat(list-item): Add dragDisabled property. #8284
Browse files Browse the repository at this point in the history
  • Loading branch information
driskull committed Nov 28, 2023
1 parent 0a9b262 commit c704ac1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/calcite-components/src/components/list-item/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
setComponentLoaded,
setUpLoadableComponent,
} from "../../utils/loadable";
import { SortableComponentItem } from "../../utils/sortableComponent";

/**
* @slot - A slot for adding `calcite-list-item` and `calcite-list-item-group` elements.
Expand All @@ -65,7 +66,12 @@ import {
assetsDirs: ["assets"],
})
export class ListItem
implements InteractiveComponent, LoadableComponent, LocalizedComponent, T9nComponent
implements
InteractiveComponent,
LoadableComponent,
LocalizedComponent,
T9nComponent,
SortableComponentItem
{
// --------------------------------------------------------------------------
//
Expand Down Expand Up @@ -113,6 +119,11 @@ export class ListItem
this.emitCalciteInternalListItemChange();
}

/**
* When `true`, the item is not draggable.
*/
@Prop({ reflect: true }) dragDisabled = false;

/**
* When `true`, the component displays a draggable button.
*
Expand Down Expand Up @@ -388,7 +399,12 @@ export class ListItem
renderDragHandle(): VNode {
return this.dragHandle ? (
<td class={CSS.dragContainer} key="drag-handle-container">
<calcite-handle label={this.label} setPosition={this.setPosition} setSize={this.setSize} />
<calcite-handle
disabled={this.dragDisabled}
label={this.label}
setPosition={this.setPosition}
setSize={this.setSize}
/>
</td>
) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ export const sortableList_TestOnly = (): string => html`<calcite-list
<calcite-list-item disabled label="test4" value="test4" description="hello world 4">
<calcite-icon icon="compass" slot="content-start" style="color: var(--calcite-ui-success)"></calcite-icon>
</calcite-list-item>
<calcite-list-item drag-disabled label="test5" value="test5" description="hello world 55">
<calcite-icon icon="compass" slot="content-start" style="color: var(--calcite-ui-success)"></calcite-icon>
</calcite-list-item>
</calcite-list>`;

export const sortableNestedList_TestOnly = (): string => html`<calcite-list
Expand Down
8 changes: 8 additions & 0 deletions packages/calcite-components/src/utils/sortableComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export interface SortableComponent {
onDragEnd: () => void;
}

export interface SortableComponentItem {
/**
* When `true`, the item is not draggable.
*/
dragDisabled: boolean;
}

/**
* Helper to keep track of a SortableComponent. This should be called in the `connectedCallback` lifecycle method as well as any other method necessary to rebuild the sortable instance.
*
Expand Down Expand Up @@ -105,6 +112,7 @@ export function connectSortableComponent(component: SortableComponent): void {
},
}),
handle,
filter: "[drag-disabled]",
onStart: () => {
dragState.active = true;
onDragStart();
Expand Down

0 comments on commit c704ac1

Please sign in to comment.