Skip to content

Commit

Permalink
Fix conditional suggestions rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
0xhyperdust committed Feb 23, 2019
1 parent acc5b56 commit b6fee3b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-ts-timepicker",
"version": "0.1.1",
"version": "0.1.2",
"description": "Simple timepicker for React",
"main": "dist/index.js",
"scripts": {
Expand Down
24 changes: 16 additions & 8 deletions src/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,11 @@ class TimePicker extends React.Component<IProps, IState> {
value,
} = this.state;

return (
const {
appendTo,
} = this.props;

const markup = (
<div
className="time-picker__suggestion-list"
ref={(el) => { this.suggestionsWrapperEl = el; }}
Expand Down Expand Up @@ -596,12 +600,21 @@ class TimePicker extends React.Component<IProps, IState> {
</button>
))}
</div>
)

if (appendTo === null) {
return markup;
}

return (
<Portal node={appendTo !== "body" && document && document.querySelector(appendTo)}>
{markup}
</Portal>
);
}

render() {
const {
appendTo,
className,
inputClass,
} = this.props;
Expand All @@ -623,12 +636,7 @@ class TimePicker extends React.Component<IProps, IState> {
ref={(el) => { this.inputEl = el; }}
/>
{((showSuggestions && suggestions.length > 0) || this.suggestionsWrapperEl) &&
appendTo === null ?
this.renderSuggestions() : (
<Portal node={appendTo !== "body" && document && document.querySelector(appendTo)}>
{this.renderSuggestions()}
</Portal>
)
this.renderSuggestions()
}
</div>
);
Expand Down

0 comments on commit b6fee3b

Please sign in to comment.