convert to static method

pull/1050/head
Cory LaViska 2022-12-06 11:37:44 -05:00
rodzic f2efa73e20
commit 69e557cd8c
3 zmienionych plików z 12 dodań i 12 usunięć

Wyświetl plik

@ -18,6 +18,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti
- Added `header-actions` slot to `<sl-dialog>` and `<sl-drawer>`
- Added the `expand-icon` and `collapse-icon` slots to `<sl-details>` and refactored the icon animation [#1046](https://github.com/shoelace-style/shoelace/discussions/1046)
- Added the `play-icon` and `pause-icon` slots to `<sl-animated-image>` so you can customize the default icons
- Converted `isTreeItem()` export to a static method of `<sl-tree-item>`
- Fixed a bug in `<sl-tree-item>` where `sl-selection-change` was emitted when the selection didn't change [#1030](https://github.com/shoelace-style/shoelace/pull/1030)
- Fixed a bug in `<sl-button-group>` that caused the border to render incorrectly when hovering over icons inside buttons [#1035](https://github.com/shoelace-style/shoelace/issues/1035)
- Fixed an incorrect default for `flip-fallback-strategy` in `<sl-popup>` that caused the fallback strategy to be `initial` instead of `best-fit`, which is inconsistent with Floating UI's default [#1036](https://github.com/shoelace-style/shoelace/issues/1036)

Wyświetl plik

@ -14,10 +14,6 @@ import '../spinner/spinner';
import styles from './tree-item.styles';
import type { CSSResultGroup, PropertyValueMap } from 'lit';
export function isTreeItem(node: Node) {
return node instanceof Element && node.getAttribute('role') === 'treeitem';
}
/**
* @summary A tree item serves as a hierarchical node that lives inside a [tree](/components/tree).
*
@ -56,6 +52,10 @@ export function isTreeItem(node: Node) {
export default class SlTreeItem extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static isTreeItem(node: Node) {
return node instanceof Element && node.getAttribute('role') === 'treeitem';
}
private readonly localize = new LocalizeController(this);
@state() indeterminate = false;
@ -185,7 +185,7 @@ export default class SlTreeItem extends ShoelaceElement {
getChildrenItems({ includeDisabled = true }: { includeDisabled?: boolean } = {}): SlTreeItem[] {
return this.childrenSlot
? ([...this.childrenSlot.assignedElements({ flatten: true })].filter(
(item: SlTreeItem) => isTreeItem(item) && (includeDisabled || !item.disabled)
(item: SlTreeItem) => SlTreeItem.isTreeItem(item) && (includeDisabled || !item.disabled)
) as SlTreeItem[])
: [];
}
@ -193,7 +193,7 @@ export default class SlTreeItem extends ShoelaceElement {
// Checks whether the item is nested into an item
private isNestedItem(): boolean {
const parent = this.parentElement;
return !!parent && isTreeItem(parent);
return !!parent && SlTreeItem.isTreeItem(parent);
}
handleChildrenSlotChange() {

Wyświetl plik

@ -4,16 +4,15 @@ import { clamp } from '../../internal/math';
import ShoelaceElement from '../../internal/shoelace-element';
import { watch } from '../../internal/watch';
import { LocalizeController } from '../../utilities/localize';
import { isTreeItem } from '../tree-item/tree-item';
import SlTreeItem from '../tree-item/tree-item';
import styles from './tree.styles';
import type SlTreeItem from '../tree-item/tree-item';
import type { CSSResultGroup } from 'lit';
function syncCheckboxes(changedTreeItem: SlTreeItem) {
function syncAncestors(treeItem: SlTreeItem) {
const parentItem: SlTreeItem | null = treeItem.parentElement as SlTreeItem;
if (isTreeItem(parentItem)) {
if (SlTreeItem.isTreeItem(parentItem)) {
const children = parentItem.getChildrenItems({ includeDisabled: false });
const allChecked = !!children.length && children.every(item => item.selected);
const allUnchecked = children.every(item => !item.selected && !item.indeterminate);
@ -143,8 +142,8 @@ export default class SlTree extends ShoelaceElement {
handleTreeChanged = (mutations: MutationRecord[]) => {
for (const mutation of mutations) {
const addedNodes: SlTreeItem[] = [...mutation.addedNodes].filter(isTreeItem) as SlTreeItem[];
const removedNodes = [...mutation.removedNodes].filter(isTreeItem) as SlTreeItem[];
const addedNodes: SlTreeItem[] = [...mutation.addedNodes].filter(SlTreeItem.isTreeItem) as SlTreeItem[];
const removedNodes = [...mutation.removedNodes].filter(SlTreeItem.isTreeItem) as SlTreeItem[];
addedNodes.forEach(this.initTreeItem);
@ -343,7 +342,7 @@ export default class SlTree extends ShoelaceElement {
}
// If the target is a tree item, update the tabindex
if (isTreeItem(target) && !target.disabled) {
if (SlTreeItem.isTreeItem(target) && !target.disabled) {
if (this.lastFocusedItem) {
this.lastFocusedItem.tabIndex = -1;
}