Skip to content

Commit

Permalink
feat(dropdown): added isMaxHeight property
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanblimaig committed Sep 4, 2023
1 parent aea3147 commit 966bd93
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/yoga/src/Dropdown/web/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Wrapper = styled.div`
position: relative;
display: inline-block;
vertical-align: top;
width: ${full ? '100%' : `${dropdown.width}px`};
`}
`;
Expand Down Expand Up @@ -152,6 +152,7 @@ const Button = styled.button`

const OptionsList = styled.ul`
${({
isMaxHeight,
theme: {
yoga: {
components: { dropdown },
Expand All @@ -164,7 +165,6 @@ const OptionsList = styled.ul`
box-sizing: border-box;
width: 100%;
max-height: ${dropdown.option.height * 3.5}px;
margin: 0;
padding: 0;
overflow-y: auto;
Expand All @@ -181,6 +181,8 @@ const OptionsList = styled.ul`
${dropdown.option.border.radius.topRight}px
${dropdown.option.border.radius.bottomRight}px
${dropdown.option.border.radius.bottomLeft}px;
${isMaxHeight && `max-height: ${dropdown.option.height * 3.5}px;`}
`}
`;

Expand Down Expand Up @@ -267,7 +269,10 @@ const ArrowIcon = styled(({ isOpen, selected, ...props }) => (

/** Gympass Dropdown is a multiple choice type of menu. */
const Dropdown = React.forwardRef(
({ error, label, disabled, full, options, onChange, ...rest }, ref) => {
(
{ error, label, disabled, full, options, onChange, isMaxHeight, ...rest },
ref,
) => {
const inputRef = ref || React.useRef(null);
const selectedOption = options.find(item => item.selected === true);
const [localSelectedItem, setLocalSelectedItem] = useState(selectedOption);
Expand Down Expand Up @@ -333,7 +338,11 @@ const Dropdown = React.forwardRef(
</Button>
</Selector>
{isOpen && (
<OptionsList selected={selectedItem !== null} {...getMenuProps()}>
<OptionsList
isMaxHeight={isMaxHeight}
selected={selectedItem !== null}
{...getMenuProps()}
>
{options.map((item, index) => (
<Option
{...getItemProps({
Expand Down Expand Up @@ -370,6 +379,7 @@ Dropdown.propTypes = {
}),
).isRequired,
onChange: func,
isMaxHeight: bool,
};

Dropdown.defaultProps = {
Expand All @@ -378,6 +388,7 @@ Dropdown.defaultProps = {
full: false,
disabled: false,
onChange: () => {},
isMaxHeight: true,
};

export default Dropdown;

0 comments on commit 966bd93

Please sign in to comment.