Skip to content
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

[WIP]: S2 treeview haschildnodes #7694

Draft
wants to merge 1 commit into
base: s2-treeview-api-update
Choose a base branch
from

Conversation

snowystinger
Copy link
Member

Closes

Attempt at fixing #7613 (comment)

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Jan 31, 2025

@rspbot
Copy link

rspbot commented Jan 31, 2025

## API Changes

react-aria-components

/react-aria-components:UNSTABLE_TreeItem

 UNSTABLE_TreeItem <T extends {}> {
   aria-label?: string
   children: ReactNode
   className?: string | ((TreeItemRenderProps & {
     defaultClassName: string | undefined
 })) => string
   download?: boolean | string
+  hasChildItems?: boolean
   href?: Href
   hrefLang?: string
   id?: Key
   onHoverChange?: (boolean) => void
   onHoverStart?: (HoverEvent) => void
   ping?: string
   referrerPolicy?: HTMLAttributeReferrerPolicy
   rel?: string
   routerOptions?: RouterOptions
   style?: CSSProperties | ((TreeItemRenderProps & {
     defaultStyle: CSSProperties
 })) => CSSProperties | undefined
   target?: HTMLAttributeAnchorTarget
   textValue: string
   value?: {}
 }

/react-aria-components:TreeItemProps

 TreeItemProps <T = {}> {
   aria-label?: string
   children: ReactNode
   className?: string | ((TreeItemRenderProps & {
     defaultClassName: string | undefined
 })) => string
   download?: boolean | string
+  hasChildItems?: boolean
   href?: Href
   hrefLang?: string
   id?: Key
   onHoverChange?: (boolean) => void
   onHoverStart?: (HoverEvent) => void
   ping?: string
   referrerPolicy?: HTMLAttributeReferrerPolicy
   rel?: string
   routerOptions?: RouterOptions
   style?: CSSProperties | ((TreeItemRenderProps & {
     defaultStyle: CSSProperties
 })) => CSSProperties | undefined
   target?: HTMLAttributeAnchorTarget
   textValue: string
   value?: T
 }

@react-aria/gridlist

/@react-aria/gridlist:AriaGridListItemOptions

 AriaGridListItemOptions {
+  hasChildItems?: boolean
   isVirtualized?: boolean
   node: Node<unknown>
   shouldSelectOnPressUp?: boolean
 }

@react-aria/tree

/@react-aria/tree:AriaTreeGridListItemOptions

 AriaTreeGridListItemOptions {
+  hasChildItems?: boolean
   node: Node<unknown>
   shouldSelectOnPressUp?: boolean
 }

@react-spectrum/s2

/@react-spectrum/s2:TreeItemContent

+TreeItemContent {
+
+}

@react-spectrum/tree

/@react-spectrum/tree:TreeItemContent

+TreeItemContent {
+
+}

/@react-spectrum/tree:Collection

+Collection <T extends {}> {
+  addIdAndValue?: boolean
+  children?: ReactNode | ({}) => ReactNode
+  dependencies?: Array<any>
+  idScope?: Key
+  items?: Iterable<{}>
+}

@@ -257,7 +257,18 @@ export class ElementNode<T> extends BaseNode<T> {
node.parentKey = this.parentNode instanceof ElementNode ? this.parentNode.node.key : null;
node.prevKey = this.previousSibling?.node.key ?? null;
node.nextKey = this.nextSibling?.node.key ?? null;
node.hasChildNodes = !!this.firstChild;

// Check if this node has any child nodes, but specifically any that are items.
Copy link
Member Author

@snowystinger snowystinger Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really a valid assumption? what about branch children? other types of items?

@snowystinger snowystinger changed the base branch from main to s2-treeview-api-update February 4, 2025 06:45
@@ -398,7 +398,7 @@ export class SelectionManager implements MultipleSelectionManager {
}

// Add child keys. If cell selection is allowed, then include item children too.
if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {
if (item && (item?.firstChildKey === undefined ? item?.hasChildNodes : item?.firstChildKey != null) && (this.allowsCellSelection || item.type !== 'item')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to account for old collections which don't have firstChildKey on their nodes

@@ -215,6 +215,10 @@ export interface Node<T> {
prevKey?: Key | null,
/** The key of the node after this node. */
nextKey?: Key | null,
/** The key of the first child node. */
firstChildKey?: Key | null,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to expose these? doesn't match old collections

@@ -58,7 +58,7 @@ class TableCollection<T> extends BaseCollection<T> implements ITableCollection<T
switch (node.type) {
case 'column':
columnKeyMap.set(node.key, node);
if (!node.hasChildNodes) {
if (node.firstChildKey == null) {
Copy link
Member Author

@snowystinger snowystinger Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is technically what the old check was, is this still actually what we want to check, it's a bit of a strange check
but things break if I update it to the new hasChildNodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants