Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AutoComplete): weird style when it's not focused anymore #217

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/forms/auto-complete/RuiAutoComplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ describe('autocomplete', () => {
expect(itemButton.innerHTML).toContain('India');
itemButton.click();

await nextTick();
const input = wrapper.find('div[data-id=activator] input').element as HTMLInputElement;
expect(input.value).toMatch('');
expect(input.classList).toContain('h-0');

let newValue = ['7', '8', '6'];
expect(wrapper.emitted().input!.at(-1)![0]).toEqual(newValue);

Expand Down
14 changes: 12 additions & 2 deletions src/components/forms/auto-complete/RuiAutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ watch(focusedValueIndex, (index) => {
});

function moveSelectedValueHighlight(event: KeyboardEvent, next: boolean) {
if (!get(multiple))
if (!get(multiple) || get(internalSearch).length > 0)
return;

event.preventDefault();
Expand Down Expand Up @@ -493,6 +493,16 @@ function setSelectionRange(start: number, end: number) {
get(textInput)?.setSelectionRange?.(start, end);
}

const inputClass: ComputedRef<string> = computed(() => {
if ((!get(anyFocused) || get(disabled)) && !get(shouldApplyValueAsSearch))
return 'w-0 h-0';

if (get(internalSearch))
return 'flex-1 min-w-[4rem]';

return 'flex-1 min-w-0';
});

defineExpose({
focus: setInputFocus,
setSelectionRange,
Expand Down Expand Up @@ -632,7 +642,7 @@ defineExpose({
class="bg-transparent outline-none"
type="text"
:placeholder="placeholder"
:class="(!anyFocused || disabled) && multiple ? 'w-0 h-0' : 'flex-1 min-w-[4rem]'"
:class="inputClass"
@keydown.delete="onInputDeletePressed()"
@input="updateSearchInput($event)"
@focus="onInputFocused()"
Expand Down
Loading