How to use the @leafygreen-ui/lib.isComponentType function in @leafygreen-ui/lib

To help you get started, we’ve selected a few @leafygreen-ui/lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / leafygreen-ui / packages / menu / src / Menu.tsx View on Github external
const updatedChildren = React.Children.map(children, child => {
    if (
      (isComponentType(child, 'MenuItem') && !child.props.disabled) ||
      isComponentType(child, 'FocusableMenuItem')
    ) {
      return React.cloneElement(child, {
        ref: (ref: HTMLElement) => {
          refs.push(ref);
          if (
            open &&
            refs.length === 1 &&
            hasSetInitialFocus.current === false
          ) {
            refs[0].focus();
            setFocused(refs[0]);
            hasSetInitialFocus.current = true;
          }
        },
        onFocus: (e: Event) => setFocused(e.target as HTMLElement),
      });
github mongodb / leafygreen-ui / packages / menu / src / Menu.tsx View on Github external
const updatedChildren = React.Children.map(children, child => {
    if (
      (isComponentType(child, 'MenuItem') && !child.props.disabled) ||
      isComponentType(child, 'FocusableMenuItem')
    ) {
      return React.cloneElement(child, {
        ref: (ref: HTMLElement) => {
          refs.push(ref);
          if (
            open &&
            refs.length === 1 &&
            hasSetInitialFocus.current === false
          ) {
            refs[0].focus();
            setFocused(refs[0]);
            hasSetInitialFocus.current = true;
          }
        },
        onFocus: (e: Event) => setFocused(e.target as HTMLElement),
github mongodb / leafygreen-ui / packages / tabs / src / Tabs.tsx View on Github external
const tabs = React.Children.map(children, (child, index) => {
    if (!isComponentType(child, 'Tab')) {
      return child;
    }

    return React.cloneElement(child, {
      key: index,
      ariaControl: `tab-${index}`,
      selected: selected === index,
    });
  });