Skip to content

Commit

Permalink
fix(AutoComplete): change style of input when not focused
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Jun 20, 2024
1 parent 959e741 commit f0c2e37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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 @@ -180,6 +180,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('update:modelValue')?.[0]).toEqual([newValue]);

Expand Down
12 changes: 10 additions & 2 deletions src/components/forms/auto-complete/RuiAutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ watch(focusedValueIndex, async (index) => {
});
function moveSelectedValueHighlight(event: KeyboardEvent, next: boolean): void {
if (!get(multiple))
if (!get(multiple) || get(internalSearch).length > 0)
return;
event.preventDefault();
Expand Down Expand Up @@ -367,6 +367,14 @@ const { focused: noDataContainerFocusedWithin } = useFocusWithin(noDataContainer
const { focused: menuFocusedWithin } = useFocusWithin(containerProps.ref);
const anyFocused = logicOr(activatorFocusedWithin, noDataContainerFocusedWithin, menuFocusedWithin);
const inputClass = computed<string>(() => {
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';
});
function textValueToProperValue(val: any): T {
const keyAttr = props.keyAttr;
const textAttr = props.textAttr;
Expand Down Expand Up @@ -618,7 +626,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

0 comments on commit f0c2e37

Please sign in to comment.