diff --git a/src/components/Box/Box.tsx b/src/components/Box/Box.tsx index cc548ec..832edf1 100644 --- a/src/components/Box/Box.tsx +++ b/src/components/Box/Box.tsx @@ -61,6 +61,7 @@ export interface ExtendedBoxProps extends BoxProps { // breakpoints sm?: customStyles; md?: customStyles; + lp?: customStyles; lg?: customStyles; direction?: "row" | "column" | "row-reverse" | "column-reverse"; diff --git a/src/components/Chip/Chip.styles.ts b/src/components/Chip/Chip.styles.ts index 80d9dba..32b642b 100644 --- a/src/components/Chip/Chip.styles.ts +++ b/src/components/Chip/Chip.styles.ts @@ -69,7 +69,7 @@ const StyledChip = styled.div<{ padding: 0 ${({theme}) => theme.spacing.xs}; height: ${({theme, size}) => theme.spacing[size]}; line-height: ${({theme, size}) => theme.spacing[size]}; - border-radius: ${({theme}) => theme.borderRadius.minimal}; + border-radius: ${({theme}) => theme.borderRadius.base}; color: ${({theme, role, priority}) => propsToColour(theme, role, priority)}; display: inline-flex; justify-content: center; @@ -81,7 +81,7 @@ const StyledChip = styled.div<{ props.role === "default" && props.priority === "low" && ` - border: 1px solid ${props.theme.core.border.borderMedium}; + border: 1px solid ${props.theme.core.border.borderLight}; `} ${(props) => addCustomStyles(props)}; diff --git a/src/components/Dropdown/Dropdown.test.tsx b/src/components/Dropdown/Dropdown.test.tsx index 4236730..8139b06 100644 --- a/src/components/Dropdown/Dropdown.test.tsx +++ b/src/components/Dropdown/Dropdown.test.tsx @@ -126,4 +126,25 @@ describe("Dropdown Component", () => { expect(getByText("inline-loading")).toBeInTheDocument(); }); }); + + it("shows inputvalue in input if provided", async () => { + const {getByRole} = render( + + ); + const input = getByRole("textbox"); + + expect(input).toHaveValue("Super cool option"); + }); + + it("fires event if user types in Input if onInputChange is provided", async () => { + const onInputChange = jest.fn(); + const {getByRole} = render( + + ); + const input = getByRole("textbox"); + + fireEvent.change(input, {target: {value: "Super cool option"}}); + + expect(onInputChange).toHaveBeenCalledWith(expect.anything()); + }); }); diff --git a/src/components/Dropdown/Dropdown.tsx b/src/components/Dropdown/Dropdown.tsx index 6c5fc20..533e6a7 100644 --- a/src/components/Dropdown/Dropdown.tsx +++ b/src/components/Dropdown/Dropdown.tsx @@ -10,12 +10,14 @@ import Popover from "../Popover"; import {ListItem} from "../List"; import Chip from "../Chip"; import {faChevronDown, faSearch} from "@fortawesome/pro-regular-svg-icons"; +import {customStyles} from "../../core/styleFunctions"; export interface Option { id: string | number; text: string; selected?: boolean; category?: string; + startAdornment?: React.ReactNode; endAdornment?: React.ReactNode; } @@ -31,6 +33,9 @@ export interface DropdownProps { hasClearSelection?: boolean; hasSelectAll?: boolean; hasSearch?: boolean; + inputValue?: string; + onInputChange?: (e: React.ChangeEvent) => void; + endAdornment?: React.ReactNode; onChange?: (selectedValue: any, previouslySelected: boolean) => void; onClearSelection?: () => void; onSelectAll?: () => void; @@ -39,6 +44,7 @@ export interface DropdownProps { "data-cy"?: string; loadingIndicator?: React.ReactNode; selectedIndicator?: React.ReactNode; + cs?: customStyles; } /** @@ -60,6 +66,9 @@ const Dropdown = ({ hasClearSelection = false, hasSelectAll = false, hasSearch = false, + inputValue, + onInputChange, + endAdornment, onChange = () => {}, onClearSelection = () => {}, onSelectAll = () => {}, @@ -68,11 +77,11 @@ const Dropdown = ({ "data-cy": dataCy, loadingIndicator, selectedIndicator, + cs, }: DropdownProps) => { const popRef = useRef(null); const [showPopover, setShowPopover] = useState(false); // eslint-disable-next-line - const [value, setValue] = useState(defaultValue); const [searchTerm, setSearchTerm] = useState(""); const selectedCount = [ ...new Set( @@ -105,59 +114,64 @@ const Dropdown = ({ setShowPopover(false); }} > - + { setShowPopover(true); }} endAdornment={ - - {hasSelectedCount ? ( - !notSelectedCount ? ( - // needed to disable because eslint is looking for aria attribute role - // eslint-disable-next-line - - ALL - - ) : selectedCount ? ( - // needed to disable because eslint is looking for aria attribute role - // eslint-disable-next-line - - {selectedCount} - - ) : null - ) : null} - { - setShowPopover(true); + endAdornment || ( + - + > + {hasSelectedCount ? ( + !notSelectedCount ? ( + // needed to disable because eslint is looking for aria attribute role + // eslint-disable-next-line + + ALL + + ) : selectedCount ? ( + // needed to disable because eslint is looking for aria attribute role + // eslint-disable-next-line + + {selectedCount} + + ) : null + ) : null} + { + setShowPopover(true); + }} + /> + + ) } fullWidth ref={popRef} label={label} placeholder={placeholder} value={ - multipleSelect + typeof inputValue === "string" + ? inputValue + : multipleSelect ? selectedCount ? label : "" : options?.find((item: any) => item?.id === defaultValue)?.text || "" } - readOnly={true} + readOnly={typeof inputValue !== "string"} /> {showPopover ? ( `@media (min-width:${values[key]}px)`, };