From 4c914bd5b78a1c7571103e16eda1b97a52506e67 Mon Sep 17 00:00:00 2001 From: unix Date: Sun, 12 Apr 2020 08:16:12 +0800 Subject: [PATCH] fix(select): limit the maximum height of the dropdown-menu --- components/select/select-dropdown.tsx | 24 ++++++++++++++++++++---- components/select/select.tsx | 9 +++++++-- pages/en-us/components/select.mdx | 2 ++ pages/zh-cn/components/select.mdx | 2 ++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/components/select/select-dropdown.tsx b/components/select/select-dropdown.tsx index a466773..a91b67b 100644 --- a/components/select/select-dropdown.tsx +++ b/components/select/select-dropdown.tsx @@ -1,26 +1,42 @@ import React from 'react' import useTheme from '../styles/use-theme' +import withDefaults from '../utils/with-defaults' import { useSelectContext } from './select-context' import Dropdown from '../shared/dropdown' interface Props { visible: boolean + className?: string + dropdownStyle?: object } -const SelectDropdown: React.FC> = ({ - visible, children, +const defaultProps = { + className: '', + dropdownStyle: {}, +} + +type NativeAttrs = Omit, keyof Props> +export type SelectDropdownProps = Props & typeof defaultProps & NativeAttrs + +const SelectDropdown: React.FC> = ({ + visible, children, className, dropdownStyle, }) => { const theme = useTheme() const { ref } = useSelectContext() return ( -
+
{children}
@@ -28,4 +44,4 @@ const SelectDropdown: React.FC> = ({ ) } -export default SelectDropdown +export default withDefaults(SelectDropdown, defaultProps) diff --git a/components/select/select.tsx b/components/select/select.tsx index 521b999..20d83f9 100644 --- a/components/select/select.tsx +++ b/components/select/select.tsx @@ -19,6 +19,8 @@ interface Props { onChange?: (value: string) => void pure?: boolean className?: string + dropdownClassName?: string + dropdownStyle?: object } const defaultProps = { @@ -34,7 +36,8 @@ export type SelectProps = Props & typeof defaultProps & NativeAttrs const Select: React.FC> = ({ children, size, disabled, initialValue: init, value: customValue, - icon: Icon, onChange, className, pure, placeholder, ...props + icon: Icon, onChange, className, pure, placeholder, dropdownClassName, + dropdownStyle, ...props }) => { const theme = useTheme() const ref = useRef(null) @@ -81,7 +84,9 @@ const Select: React.FC> = ({
{!value && {placeholder}} {value && {selectedChild}} - {children} + {children} {!pure &&
}