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

fix: S2 treeview haschildnodes #7694

Merged
merged 2 commits into from
Feb 11, 2025

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

@snowystinger snowystinger changed the title [WIP]: S2 treeview haschildnodes fix: S2 treeview haschildnodes Feb 11, 2025
@snowystinger snowystinger marked this pull request as ready for review February 11, 2025 22:54
@snowystinger snowystinger merged commit 9e7b7b2 into s2-treeview-api-update Feb 11, 2025
3 of 8 checks passed
@snowystinger snowystinger deleted the s2-treeview-haschildnodes branch February 11, 2025 22:54
github-merge-queue bot pushed a commit that referenced this pull request Feb 12, 2025
* chore: Update TreeView API

* fix docs

* fix dynamic example

* actually save

* fix docs

* review comments

* Revert change to not use hasChildItems

* add prop table

* fix docs example

* remove extra border attributes in theme

* fix snapshots

* fix: S2 treeview haschildnodes (#7694)

* fix logic to determine hasChildNodes

* revert breaking changes but use prop override

* match rac logic with hook

* Fix spacing regression

* fix chromatic merge

* fix lint
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