diff --git a/packages/ui-drilldown/src/Drilldown/index.tsx b/packages/ui-drilldown/src/Drilldown/index.tsx index e358302ed6..01fc808827 100644 --- a/packages/ui-drilldown/src/Drilldown/index.tsx +++ b/packages/ui-drilldown/src/Drilldown/index.tsx @@ -893,7 +893,7 @@ class Drilldown extends Component { // Use action ID if exists, otherwise first non-action option's ID const targetId = actionLabel ? this._headerActionId - : this.currentPage.children[0]?.props.id + : this.getFirstOption()?.props.id setTimeout(() => { this.setState({ highlightedOptionId: targetId @@ -911,6 +911,24 @@ class Drilldown extends Component { } } + getFirstOption = () => { + const children = Children.toArray(this.currentPage?.children) + + const child = children[0] + if (!child) return undefined + + // If it's a regular option, return it + if (matchComponentTypes(child, [DrilldownOption])) { + return child + } + // If it's a group, get its options + if (matchComponentTypes(child, [Drilldown.Group])) { + const groupOptions = Children.toArray(child.props.children) + return groupOptions[0] as OptionChild + } + return undefined + } + renderList( getOptionProps: SelectableRender['getOptionProps'], getDisabledOptionProps: SelectableRender['getDisabledOptionProps'] @@ -1512,7 +1530,7 @@ class Drilldown extends Component { // Use action ID if exists, otherwise first non-action option's ID const targetId = actionLabel ? this._headerActionId - : this.currentPage.children[0]?.props.id + : this.getFirstOption()?.props.id if (!targetId) return null return this._popover?._contentElement?.querySelector(