Commit bac2de2f authored by LexSwed's avatar LexSwed
Browse files

fix: Select children validation

parent 94b80c55
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
export { default as Box } from 'components/Box';
export { default as Button } from 'components/Button';
export { default as Card } from 'components/Card';
export { default as Dropdown } from 'components/Dropdown';
export { default as Icon } from 'components/Icon';
export { default as Option } from 'components/Option';
export { default as Select } from 'components/Select';
export { default as TextField } from 'components/TextField';
export { default as ThemeProvider } from 'components/ThemeProvider';

+0 −1
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ import Icon from 'components/Icon';

import { useDownshiftOptions } from './utils';
import styled, { css } from 'styled-components';
import { Size } from 'types/helpers';

const hiddenStyles = css`
  opacity: 0;
+12 −11
Original line number Diff line number Diff line
import React, { useMemo, ReactNodeArray, FunctionComponent } from 'react';
import React, { ReactNodeArray, FunctionComponent } from 'react';

import Dropdown from 'components/Dropdown';
import Option from 'components/Option';
@@ -12,16 +12,6 @@ const SelectDropdown: FunctionComponent<Props> = ({ content, filter, children, .
  const { getMenuProps, isOpen } = useDownshiftOptions();
  const filtered = useFilteredItems(content, filter);

  const isValidChildren = useMemo(() => {
    return React.Children.toArray(content).every(child => {
      return React.isValidElement(child) && child.type === Option;
    });
  }, [content]);

  if (!isValidChildren) {
    throw Error('Content` prop is an array of `Option` instances');
  }

  return (
    <Dropdown isOpen={isOpen} content={filtered} {...getMenuProps()} {...props}>
      {children}
@@ -29,4 +19,15 @@ const SelectDropdown: FunctionComponent<Props> = ({ content, filter, children, .
  );
};

SelectDropdown.propTypes = {
  content(props, propName, componentName) {
    const isValidChildren = React.Children.toArray(props[propName]).every(
      child => React.isValidElement(child) && child.type === Option
    );
    if (!isValidChildren) {
      return new Error(`${componentName} only accepts "<Option />" elements`);
    }
  }
};

export default SelectDropdown;
+1 −1
Original line number Diff line number Diff line
import React, { FunctionComponent, ReactText } from 'react';
import Downshift from 'downshift';

import { useDownshift, DownshiftContext, OptionElement } from './utils';
import { useDownshift, DownshiftContext } from './utils';
import Dropdown from './Dropdown.helper';
import Input from 'components/TextField';
import SelectInput from './SelectInput.helper';
+0 −2
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@ import React, {
  createContext,
  useContext,
  ReactText,
  ReactElement,
  ReactNode,
  useRef,
  useEffect,
  useLayoutEffect,
Loading