Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit df6f0fa

Browse files
committed
fix(AutoComplete): some issues
1 parent 76241a5 commit df6f0fa

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

src/components/forms/auto-complete/RuiAutoComplete.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,16 @@ function getListeners(on: Record<string, Function | undefined>, $listeners: Reco
447447
...listenersFiltered,
448448
};
449449
}
450+
451+
function setInputSelectionRange(start: number, end: number) {
452+
set(searchInputFocused, true);
453+
get(textInput)?.setSelectionRange?.(start, end);
454+
}
455+
456+
defineExpose({
457+
setInputFocus,
458+
setInputSelectionRange,
459+
});
450460
</script>
451461

452462
<template>
@@ -459,6 +469,10 @@ function getListeners(on: Record<string, Function | undefined>, $listeners: Reco
459469
fullWidth: true,
460470
persistOnActivatorClick: true,
461471
...menuOptions,
472+
menuClass: [
473+
{ hidden: (optionsWithSelectedHidden.length === 0 && customValue && !slots['no-data']) },
474+
menuOptions?.menuClass,
475+
],
462476
errorMessages,
463477
successMessages,
464478
hint,

src/components/overlays/menu/Menu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export interface MenuProps {
1111
openDelay?: number;
1212
closeDelay?: number;
1313
popper?: PopperOptions;
14-
wrapperClass?: string;
15-
menuClass?: string;
14+
wrapperClass?: any;
15+
menuClass?: any;
1616
closeOnContentClick?: boolean;
1717
persistOnActivatorClick?: boolean;
1818
hint?: string;

src/composables/dropdown-menu.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,28 @@ export function useDropdownMenu<T, K extends keyof T>({
138138

139139
function adjustScrollByHighlightedIndex(smooth: boolean = false) {
140140
const index = get(highlightedIndex);
141-
nextTick(() => {
142-
const container = get(menuRef)?.parentElement;
143-
if (container && index > -1) {
144-
const highlightedElem = get(menuRef).getElementsByClassName('highlighted')[0];
145-
146-
if (highlightedElem) {
147-
highlightedElem.scrollIntoView?.({ behavior: smooth ? 'smooth' : 'auto', block: 'nearest' });
148-
if (get(autoFocus) && 'focus' in highlightedElem && typeof highlightedElem.focus === 'function')
149-
highlightedElem?.focus();
150-
}
151-
else {
152-
scrollTo(index);
153-
if (get(autoFocus)) {
154-
const elem = get(menuRef).getElementsByClassName('highlighted')[0];
155-
if (elem && 'focus' in elem && typeof elem.focus === 'function')
156-
elem.focus();
141+
if (index > -1) {
142+
nextTick(() => {
143+
const container = get(menuRef)?.parentElement;
144+
if (container) {
145+
const highlightedElem = get(menuRef).getElementsByClassName('highlighted')[0];
146+
147+
if (highlightedElem) {
148+
highlightedElem.scrollIntoView?.({ behavior: smooth ? 'smooth' : 'auto', block: 'nearest' });
149+
if (get(autoFocus) && 'focus' in highlightedElem && typeof highlightedElem.focus === 'function')
150+
highlightedElem?.focus();
151+
}
152+
else {
153+
scrollTo(index);
154+
if (get(autoFocus)) {
155+
const elem = get(menuRef).getElementsByClassName('highlighted')[0];
156+
if (elem && 'focus' in elem && typeof elem.focus === 'function')
157+
elem.focus();
158+
}
157159
}
158160
}
159-
}
160-
});
161+
});
162+
}
161163
}
162164

163165
function updateOpen(open: boolean) {
@@ -193,12 +195,16 @@ export function useDropdownMenu<T, K extends keyof T>({
193195
if (get(highlightedIndex) !== -1) {
194196
if (get(autoSelectFirst)) {
195197
set(highlightedIndex, 0);
198+
adjustScrollByHighlightedIndex();
196199
}
197200
else {
198201
set(highlightedIndex, -1);
199202
scrollTo(0);
200203
}
201204
}
205+
else {
206+
scrollTo(0);
207+
}
202208
});
203209

204210
const moveHighlight = (up: boolean) => {

0 commit comments

Comments
 (0)