Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(ui): prevent Select from overflowing bottom screen bound
Browse files Browse the repository at this point in the history
  • Loading branch information
korhaliv committed Sep 5, 2019
1 parent 662c6fe commit 0c0e7e6
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions renderer/components/Form/Select.js
Expand Up @@ -7,7 +7,7 @@ import styled, { withTheme } from 'styled-components'
import { themeGet } from '@styled-system/theme-get'
import Downshift from 'downshift'
import { Box, Flex } from 'rebass/styled-components'
import { useIntl } from 'hooks'
import { useIntl, useMaxScreenHeight } from 'hooks'
import Check from 'components/Icon/Check'
import AngleUp from 'components/Icon/AngleUp'
import AngleDown from 'components/Icon/AngleDown'
Expand All @@ -23,7 +23,7 @@ const SelectOptionList = styled.ul`
position: absolute;
z-index: 2;
width: 100%;
max-height: 20rem;
max-height: ${props => props.maxHeight}px;
overflow-y: auto;
overflow-x: hidden;
outline: 0;
Expand Down Expand Up @@ -78,6 +78,28 @@ const getInitialSelectedItem = (items, initialSelectedItem) => {
}
: {}
}
const SelectOptionListContainer = props => {
const { highlightedIndex, selectedItem, getItemProps, getMenuProps, renderSelectOptions } = props
const [measuredRef, maxHeight] = useMaxScreenHeight(300)
const height = maxHeight < 150 ? undefined : maxHeight
return (
<SelectOptionList
{...getMenuProps({}, { suppressRefError: true })}
ref={measuredRef}
maxHeight={height}
>
{renderSelectOptions(highlightedIndex, selectedItem, getItemProps)}
</SelectOptionList>
)
}

SelectOptionListContainer.propTypes = {
getItemProps: PropTypes.func.isRequired,
getMenuProps: PropTypes.func.isRequired,
highlightedIndex: PropTypes.number,
renderSelectOptions: PropTypes.func.isRequired,
selectedItem: PropTypes.object,
}

const Select = props => {
const { intl, messageMapper } = props
Expand Down Expand Up @@ -219,9 +241,15 @@ const Select = props => {
</Box>
</Flex>
{isOpen && (
<SelectOptionList {...getMenuProps({}, { suppressRefError: true })}>
{renderSelectOptions(highlightedIndex, selectedItem, getItemProps)}
</SelectOptionList>
<SelectOptionListContainer
{...{
getMenuProps,
renderSelectOptions,
highlightedIndex,
selectedItem,
getItemProps,
}}
/>
)}
</Box>
)
Expand Down

0 comments on commit 0c0e7e6

Please sign in to comment.