import React from "react";

export default class MenuWrap extends React.Component<any, any> {
  innerMenu = {
    onKeyNavNodeKeyDown: () => {},
  };
  render() {
    const ret =
      React.Children.count(this.props.children) == 1
        ? React.cloneElement(React.Children.only(this.props.children as any), {
            ref: (n: any) => {
              this.innerMenu = n;
            },
          })
        : this.props.children;
    return <div {...this.props}>{ret}</div>;
  }

  onKeyNavNodeKeyDown(...args: any[]) {
    if (this.innerMenu) {
      if (this.innerMenu.onKeyNavNodeKeyDown) {
        // @ts-ignore
        this.innerMenu.onKeyNavNodeKeyDown(...args);
      }
    }
  }
}
