Skip to content

Commit 3f822ab

Browse files
authored
boundariesElement supports dynamic dimensions (#115)
fix(autocomplete): this commit adds the ability to recalculate the position of autocomplete based on dynamic height / weight
1 parent 3524e28 commit 3f822ab

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

__tests__/__snapshots__/index.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ exports[`object-based items match the snapshot 1`] = `
2929

3030
exports[`object-based items match the snapshot of dropdown, list, and item 1`] = `
3131
<div
32-
class="rta__autocomplete rta__autocomplete--left rta__autocomplete--top "
32+
class="rta__autocomplete rta__autocomplete--right rta__autocomplete--bottom "
3333
style="top: 0px; left: 0px;"
3434
>
3535
<ul
@@ -158,7 +158,7 @@ exports[`object-based items with keys match the snapshot 1`] = `
158158

159159
exports[`object-based items with keys match the snapshot of dropdown, list, and item 1`] = `
160160
<div
161-
class="rta__autocomplete rta__autocomplete--left rta__autocomplete--top "
161+
class="rta__autocomplete rta__autocomplete--right rta__autocomplete--bottom "
162162
style="top: 0px; left: 0px;"
163163
>
164164
<ul

src/Textarea.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class Autocomplete extends React.Component<
9999
);
100100
}
101101
}
102-
103-
this._calculatePosition();
104102
}
105103

106104
_calculatePosition = () => {
@@ -142,6 +140,12 @@ class Autocomplete extends React.Component<
142140
? POSITION_CONFIGURATION.Y.BOTTOM
143141
: POSITION_CONFIGURATION.Y.TOP;
144142

143+
if (
144+
this.state.dropdownHeight === dropdownHeight &&
145+
this.state.dropdownWidth === dropdownWidth
146+
)
147+
return;
148+
145149
this.setState({
146150
xConfig,
147151
yConfig,
@@ -150,6 +154,10 @@ class Autocomplete extends React.Component<
150154
});
151155
};
152156

157+
componentDidUpdate() {
158+
this._calculatePosition();
159+
}
160+
153161
render() {
154162
const { style, className, innerRef, children, top, left } = this.props;
155163
const { xConfig, yConfig, dropdownHeight, dropdownWidth } = this.state;
@@ -202,8 +210,6 @@ class ReactTextareaAutocomplete extends React.Component<
202210
constructor(props: TextareaProps) {
203211
super(props);
204212

205-
Listeners.add(KEY_CODES.ESC, () => this._closeAutocomplete());
206-
207213
const { loadingComponent, trigger, value } = this.props;
208214

209215
if (value) this.state.value = value;
@@ -233,6 +239,7 @@ class ReactTextareaAutocomplete extends React.Component<
233239
};
234240

235241
componentDidMount() {
242+
Listeners.add(KEY_CODES.ESC, this._closeAutocomplete);
236243
Listeners.startListen();
237244
}
238245

0 commit comments

Comments
 (0)