Skip to content

Commit

Permalink
MM-14489 Making SuggestionList component render at bottom of input on…
Browse files Browse the repository at this point in the history
… dialogs (mattermost#2235)

Given a bug found that `SuggestionList`s [will clip through the top of a modal body](https://pre-release.mattermost.com/core/pl/wafwh5fyytgauykxdyytsqa51a), this PR passes along the `listStyle` prop (as an optional prop) to make it render below the input (instead of above, which is the default behavior)
  • Loading branch information
avasconcelos114 authored and hanzei committed Mar 12, 2019
1 parent 78c1c2d commit ab31a59
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions components/interactive_dialog/dialog_element.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default class DialogElement extends React.PureComponent {
helpText={helpTextContent}
placeholder={placeholder}
value={this.state.value}
listStyle={'bottom'}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion components/interactive_dialog/interactive_dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default class InteractiveDialog extends React.Component {

return (
<Modal
dialogClassName='about-modal'
dialogClassName='about-modal modal--overflow-visible'
show={this.state.show}
onHide={this.onHide}
onExited={this.props.onHide}
Expand Down
14 changes: 13 additions & 1 deletion components/suggestion/suggestion_box.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import PropTypes from 'prop-types';
import React from 'react';
import ReactDOM from 'react-dom';

import EventEmitter from 'mattermost-redux/utils/event_emitter';

Expand Down Expand Up @@ -170,6 +171,8 @@ export default class SuggestionBox extends React.Component {
selection: '',
allowDividers: true,
presentationType: 'text',
dropdownPosition: 0,
inputWidth: 0,
};
}

Expand Down Expand Up @@ -266,8 +269,8 @@ export default class SuggestionBox extends React.Component {
return;
}

this.getDropdownPosition();
this.setState({focused: true});

if (this.props.openOnFocus || this.props.openWhenEmpty) {
setTimeout(() => {
const textbox = this.getTextbox();
Expand Down Expand Up @@ -598,6 +601,13 @@ export default class SuggestionBox extends React.Component {
this.container = container;
};

getDropdownPosition = () => {
const input = ReactDOM.findDOMNode(this.refs.input);
const dropdownPosition = input.getBoundingClientRect().top;
const inputWidth = input.clientWidth;
this.setState({dropdownPosition, inputWidth});
}

render() {
const {
listComponent,
Expand Down Expand Up @@ -661,6 +671,8 @@ export default class SuggestionBox extends React.Component {
terms={this.state.terms}
selection={this.state.selection}
components={this.state.components}
dropdownPosition={this.state.dropdownPosition}
inputWidth={this.state.inputWidth}
/>
}
{(this.props.openWhenEmpty || this.props.value.length >= this.props.requiredCharacters) && this.state.presentationType === 'date' &&
Expand Down
12 changes: 11 additions & 1 deletion components/suggestion/suggestion_list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class SuggestionList extends React.PureComponent {
terms: PropTypes.array.isRequired,
selection: PropTypes.string.isRequired,
components: PropTypes.array.isRequired,
dropdownPosition: PropTypes.number,
inputWidth: PropTypes.number,
};

static defaultProps = {
Expand Down Expand Up @@ -161,8 +163,16 @@ export default class SuggestionList extends React.PureComponent {
const mainClass = 'suggestion-list suggestion-list--' + this.props.location;
const contentClass = 'suggestion-list__content suggestion-list__content--' + this.props.location;

let style = {};
if (this.props.dropdownPosition && this.props.location === 'bottom') {
style = {top: this.props.dropdownPosition + 5, width: this.props.inputWidth};
}

return (
<div className={mainClass}>
<div
className={mainClass}
style={style}
>
<div
id='suggestionList'
ref='content'
Expand Down
3 changes: 3 additions & 0 deletions components/widgets/settings/autocomplete_selector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class AutocompleteSelector extends React.PureComponent {
helpText: PropTypes.node,
placeholder: PropTypes.string,
footer: PropTypes.node,
listStyle: PropTypes.string,
};

static defaultProps = {
Expand Down Expand Up @@ -79,6 +80,7 @@ export default class AutocompleteSelector extends React.PureComponent {
helpText,
inputClassName,
value,
listStyle,
} = this.props;

const {focused} = this.state;
Expand Down Expand Up @@ -130,6 +132,7 @@ export default class AutocompleteSelector extends React.PureComponent {
openOnFocus={true}
openWhenEmpty={true}
replaceAllInputOnSelect={true}
listStyle={listStyle}
/>
{helpTextContent}
{footer}
Expand Down
5 changes: 2 additions & 3 deletions sass/components/_select.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@charset 'UTF-8';

.select-suggestion-container {
position: relative;
position: static;
margin: 8px 8px 0 0;

&:hover {
Expand All @@ -19,9 +19,8 @@
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
top: 8px;
bottom: 22px;
position: absolute;
right: 1rem;
opacity: .4;
font-size: 16px;
pointer-events: none;
Expand Down
7 changes: 3 additions & 4 deletions sass/components/_suggestion-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@extend %popover-box-shadow;
width: 100%;
z-index: 100;
position: absolute;

.suggestion-list__item {
&:hover {
Expand All @@ -26,12 +27,10 @@

.suggestion-list--top {
bottom: 100%;
position: absolute;
}

.suggestion-list--bottom {
height: 0;
position: relative;
}

.suggestion-list__content {
Expand Down Expand Up @@ -63,11 +62,11 @@
}

.suggestion-list__content--top {
bottom: 0;
bottom: -8px;
position: absolute;
}

.suggestion-list--bottom {
.suggestion-list__content--bottom {
position: relative;
}

Expand Down
2 changes: 1 addition & 1 deletion sass/layout/_webhooks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
}

.form-control {
.form-control, .suggestion-list {
width: 22rem;
}
}
Expand Down
20 changes: 18 additions & 2 deletions sass/routes/_about-modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,31 @@
.select-suggestion-container {
margin: 0;

.suggestion-list--top {
height: 0;
bottom: initial;
}

.suggestion-list {
width: calc(100% - 50px);

.suggestion-list__content--top {
position: relative;
bottom: initial;
transform: translateY(calc(-100% - 36px));
}
}

.form-control {
height: 36px;
padding: 8px 12px;
}

&:after {
top: 9px;
right: 12px;
left: calc(100% - 27px);
bottom: 27px;
font-size: 20px;
position: relative;
}
}

Expand Down

0 comments on commit ab31a59

Please sign in to comment.