diff --git a/src/Input/DownshiftSelect/Select.stories.tsx b/src/Input/DownshiftSelect/Select.stories.tsx index 9f9525c7b..5a6fe4145 100644 --- a/src/Input/DownshiftSelect/Select.stories.tsx +++ b/src/Input/DownshiftSelect/Select.stories.tsx @@ -379,3 +379,29 @@ ConfigurableWidth.parameters = { }, }, }; + +const SmallContainer = styled(Select.Components.Container)` + max-width: 200px; + font-size: 11px; +`; + +export const Small = Template.bind({}); +Small.args = { + label: "I'm so small!", + placeholder: 'Try typing here :-P', + components: { Container: SmallContainer }, + helperText: 'Why would you do this to me?', +}; +Small.parameters = { + docs: { + description: { + story: + "

By default, the Select dictates a font-size of 16px that cascades through (almost) all sub-components. Appropriate spaces are defined using em, so if you want to resize the Select, just change the container's font-size.

The exception to the 16px default is the helper text, which also just uses an em relative value.

", + }, + }, +}; + +export const EmptyListText = Template.bind({}); +EmptyListText.args = { + emptyListText: '¯\\_(ツ)_/¯', +}; diff --git a/src/Input/DownshiftSelect/Select.tsx b/src/Input/DownshiftSelect/Select.tsx index 139642210..a72730ff8 100644 --- a/src/Input/DownshiftSelect/Select.tsx +++ b/src/Input/DownshiftSelect/Select.tsx @@ -13,6 +13,9 @@ export const defaultTransformFunction = (items: Item[], inputValue: string) => export const defaultItemToString = (item: Item) => item.label; +export const defaultEmptyListText = + 'No results found. Try another keyword to search for.'; + export interface Components { Container: typeof internalComponents.Container; Label: typeof internalComponents.Label; @@ -24,6 +27,7 @@ export interface Components { ToggleButton: typeof internalComponents.ToggleButton; Menu: typeof internalComponents.Menu; Item: typeof internalComponents.Item; + EmptyList: typeof internalComponents.EmptyList; HelperText: typeof internalComponents.HelperText; } @@ -46,6 +50,7 @@ export type MenuProps = HTMLAttributes; export interface ItemProps extends HTMLAttributes { item: Item; } +export type EmptyListProps = HTMLAttributes; export type HelperTextProps = HTMLAttributes; export interface Props extends ComboboxProps { @@ -95,6 +100,8 @@ export interface Props extends ComboboxProps { // onInputValueChange?: (inputValue: string) => void; onClear?: () => void; + + emptyListText?: string; } export const Select: React.FC & { Components: Components } = ({ @@ -117,6 +124,9 @@ export const Select: React.FC & { Components: Components } = ({ // inputValue: inputValueExternal, // onInputValueChange: onInputValueChangeExternal, onClear, + onFocus: onFocusExternal, + onBlur: onBlurExternal, + emptyListText = defaultEmptyListText, ...props }) => { const mergedComponents = { @@ -135,6 +145,7 @@ export const Select: React.FC & { Components: Components } = ({ ToggleButton, Menu, Item, + EmptyList, HelperText, } = mergedComponents; @@ -149,6 +160,7 @@ export const Select: React.FC & { Components: Components } = ({ getMenuProps, getItemProps, reset, + openMenu, } = useCombobox({ items: displayItems, onInputValueChange: ({ inputValue }) => { @@ -191,12 +203,31 @@ export const Select: React.FC & { Components: Components } = ({ reset(); }; + const [isFocused, setIsFocused] = useState(false); + const onFocusInternal = () => { + setIsFocused(true); + openMenu(); + }; + const onBlurInternal = () => setIsFocused(false); + const onFocus = () => { + if (isFunction(onFocusExternal)) { + onFocusExternal(); + } + onFocusInternal(); + }; + const onBlur = () => { + if (isFunction(onBlurExternal)) { + onBlurExternal(); + } + onBlurInternal(); + }; + return ( {label && (