-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: conditional selectability of grid items #7974
Changes from all commits
67b7b90
3961f60
cc11334
e4b361c
9a0dd77
f64a6be
2cdf83c
6cb554c
bfa2d0a
1edd174
57bea9c
35591f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
tomivirkki marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,29 @@ export const SelectionMixin = (superClass) => | |
sync: true, | ||
}, | ||
|
||
/** | ||
* A function to check whether a specific item in the grid may be | ||
* selected or deselected by the user. Used by the selection column to | ||
* conditionally enable to disable checkboxes for individual items. This | ||
* function does not prevent programmatic selection/deselection of | ||
* items. Changing the function does not modify the currently selected | ||
* items. | ||
* | ||
* Configuring this function hides the select all checkbox of the grid | ||
* selection column, which means users can not select or deselect all | ||
* items anymore, nor do they get feedback on whether all items are | ||
* selected or not. | ||
* | ||
* Receives an item instance and should return a boolean indicating | ||
* whether users may change the selection state of that item. | ||
* | ||
* @type {(item: !GridItem) => boolean} | ||
*/ | ||
isItemSelectable: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other similar APIs, such as part name generator or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed this and decided to only pass the item. Technically we could construct a row model object from the item itself before passing it to the function, but that would potentially require iterating over all grid caches to figure out the flat row index, or whether an item is a nested one. If we later on want to add support for select all, we'll have to run this function in some way or another over all grid items, at which point this could become a performance issue. |
||
type: Function, | ||
notify: true, | ||
}, | ||
|
||
/** | ||
* Set of selected item ids | ||
* @private | ||
|
@@ -34,7 +57,7 @@ export const SelectionMixin = (superClass) => | |
} | ||
|
||
static get observers() { | ||
return ['__selectedItemsChanged(itemIdPath, selectedItems)']; | ||
return ['__selectedItemsChanged(itemIdPath, selectedItems, isItemSelectable)']; | ||
} | ||
|
||
/** | ||
|
@@ -46,6 +69,22 @@ export const SelectionMixin = (superClass) => | |
return this.__selectedKeys.has(this.getItemId(item)); | ||
} | ||
|
||
/** | ||
* Determines whether the selection state of an item may be changed by the | ||
* user. | ||
* | ||
* @private | ||
*/ | ||
__isItemSelectable(item) { | ||
// Item is selectable by default if isItemSelectable is not configured | ||
if (!this.isItemSelectable || !item) { | ||
return true; | ||
} | ||
|
||
// Otherwise, check isItemSelectable function | ||
return this.isItemSelectable(item); | ||
} | ||
|
||
/** | ||
* Selects the given item. | ||
* | ||
|
@@ -70,21 +109,6 @@ export const SelectionMixin = (superClass) => | |
} | ||
} | ||
|
||
/** | ||
* Toggles the selected state of the given item. | ||
* | ||
* @method toggle | ||
* @param {!GridItem} item The item object | ||
* @protected | ||
*/ | ||
_toggleItem(item) { | ||
if (!this._isSelected(item)) { | ||
this.selectItem(item); | ||
} else { | ||
this.deselectItem(item); | ||
} | ||
} | ||
|
||
/** @private */ | ||
__selectedItemsChanged() { | ||
this.requestContentUpdate(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import '../theme/lumo/lit-all-imports.js'; | ||
import '../src/lit-all-imports.js'; | ||
import './selectable-provider.common.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '../all-imports.js'; | ||
import './selectable-provider.common.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rolf specifically suggested to use this behavior.