Skip to content

Node.js based forum software built for the modern web

fix: autocomplete menu position in rtl (#14626)

palmoni59cfc72463a48
diff --git a/public/scss/jquery-ui.scss b/public/scss/jquery-ui.scss
index 7e705f41d5..a24310e695 100644
--- a/public/scss/jquery-ui.scss
+++ b/public/scss/jquery-ui.scss
@@ -6,3 +6,13 @@
@import 'jquery-ui/themes/base/draggable';
@import 'jquery-ui/themes/base/sortable';
@import 'jquery-ui/themes/base/theme';
+
+// jquery-ui positions its menus by setting `left` inline, so rtlcss must not
+// flip the stylesheet's `left: 0` to `right: 0` — otherwise the menu ends up
+// anchored on both edges and stretches across the page in rtl
+/*rtl:begin:ignore*/
+.ui-autocomplete {
+ left: 0;
+ right: auto;
+}
+/*rtl:end:ignore*/
diff --git a/public/src/modules/autocomplete.js b/public/src/modules/autocomplete.js
index 5466af1ded..6a5dfc6165 100644
--- a/public/src/modules/autocomplete.js
+++ b/public/src/modules/autocomplete.js
@@ -14,6 +14,7 @@ define('autocomplete', [
const { input, onSelect } = acParams;
app.loadJQueryUI(function () {
input.autocomplete({
+ position: getMenuPosition(),
...acParams,
open: function () {
$(this).autocomplete('widget').css('z-index', 100005);
@@ -120,6 +121,17 @@ define('autocomplete', [
});
};
+ // jquery-ui defaults to anchoring the menu on the left edge of the input,
+ // which is the wrong edge in rtl
+ function getMenuPosition() {
+ const edge = document.querySelector('html').getAttribute('data-dir') === 'rtl' ? 'right' : 'left';
+ return {
+ my: `${edge} top`,
+ at: `${edge} bottom`,
+ collision: 'none',
+ };
+ }
+
function handleOnSelect(input, onselect, event, ui) {
onselect = onselect || function () { };
const e = jQuery.Event('keypress');