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

Commit

Permalink
#53: DropDown can be closed from the inside
Browse files Browse the repository at this point in the history
  • Loading branch information
PzYon committed Aug 3, 2018
1 parent 439015f commit 97c207c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion client/src/common/searchBox/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from "react";
import { ChangeEvent, ReactNode } from "react";
import styled from "styled-components";
import { StyleConstants } from "../../styling/StyleConstants";
import { If } from "../If";
import { DropDown } from "./dropDown/DropDown";
import { IDropDownItemGroup } from "./dropDown/IDropDownItemGroup";
import { SelectedKeywords } from "./SelectedKeywords";
Expand Down Expand Up @@ -90,7 +91,15 @@ export class SearchBox extends React.Component<ISearchBoxProps, ISearchBoxState>
placeholder={this.state.hidePlaceholder ? "" : this.props.placeholder}
/>
</InnerContainerDiv>
{this.state.showDropDown && <DropDown groups={this.props.dropDownItemGroups} />}
<If
value={this.state.showDropDown}
render={() => (
<DropDown
groups={this.props.dropDownItemGroups}
onClose={() => this.setState({ showDropDown: false })}
/>
)}
/>
</ContainerDiv>
);
}
Expand Down
11 changes: 11 additions & 0 deletions client/src/common/searchBox/dropDown/DropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,18 @@ const GroupItem = styled.li`
}
`;

const Closer = styled.span`
position: absolute;
top: 0;
right: 0.5rem;
cursor: pointer;
font-weight: bold;
color: ${StyleConstants.colors.accent};
`;

export interface ISuggestionsProps {
groups: IDropDownItemGroup[];
onClose: () => void;
}

interface ISuggestionsState {
Expand All @@ -75,6 +85,7 @@ export class DropDown extends React.PureComponent<ISuggestionsProps, ISuggestion

return (
<ContainerDiv>
<Closer onClick={this.props.onClose}>x</Closer>
{groups.map((g: IDropDownItemGroup, index: number) => {
return (
<GroupContainerDiv key={g.title || index}>
Expand Down

0 comments on commit 97c207c

Please sign in to comment.