mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-09 11:48:47 +00:00
UX: Prevent context menu overflow outside of container (#168)
This commit is contained in:
parent
b470692409
commit
2c50791f26
@ -192,6 +192,22 @@ export default class AiHelperContextMenu extends Component {
|
|||||||
this.menuState = this.CONTEXT_MENU_STATES.review;
|
this.menuState = this.CONTEXT_MENU_STATES.review;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleBoundaries() {
|
||||||
|
const boundaryElement = document
|
||||||
|
.querySelector(".d-editor-textarea-wrapper")
|
||||||
|
.getBoundingClientRect();
|
||||||
|
|
||||||
|
const contextMenuRect = this._contextMenu.getBoundingClientRect();
|
||||||
|
|
||||||
|
if (contextMenuRect.top < boundaryElement.top) {
|
||||||
|
this._contextMenu.classList.add("out-of-bounds");
|
||||||
|
} else if (contextMenuRect.bottom > boundaryElement.bottom) {
|
||||||
|
this._contextMenu.classList.add("out-of-bounds");
|
||||||
|
} else {
|
||||||
|
this._contextMenu.classList.remove("out-of-bounds");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@afterRender
|
@afterRender
|
||||||
positionContextMenu() {
|
positionContextMenu() {
|
||||||
this._contextMenu = document.querySelector(".ai-helper-context-menu");
|
this._contextMenu = document.querySelector(".ai-helper-context-menu");
|
||||||
@ -199,6 +215,9 @@ export default class AiHelperContextMenu extends Component {
|
|||||||
pos: caretPosition(this._dEditorInput),
|
pos: caretPosition(this._dEditorInput),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// prevent overflow of context menu outside of editor
|
||||||
|
this.handleBoundaries();
|
||||||
|
|
||||||
this.virtualElement = {
|
this.virtualElement = {
|
||||||
getBoundingClientRect: this.generateGetBoundingClientRect(
|
getBoundingClientRect: this.generateGetBoundingClientRect(
|
||||||
this._contextMenu.clientWidth,
|
this._contextMenu.clientWidth,
|
||||||
|
@ -51,6 +51,10 @@
|
|||||||
list-style: none;
|
list-style: none;
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
|
|
||||||
|
&.out-of-bounds {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user