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

[MS] Adds a popover option to search input #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
87 changes: 70 additions & 17 deletions lib/components/ms-input/MsSearchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,71 @@
class="input-content ms-search-input"
id="ms-search-input"
>
<ion-icon
:icon="search"
slot="start"
class="icon"
/>
<ion-input
class="form-input input"
ref="inputRef"
:value="modelValue"
:placeholder="$msTranslate(placeholder)"
:clear-input="true"
@ion-input="onChange($event.target.value)"
@keyup.enter="onEnterPress()"
mode="ios"
/>
<!-- mode=ios to change the clear icon style -->
<div
v-if="asPopover"
@click="openPopover"
>
<div>
<ion-icon
:icon="search"
slot="start"
class="icon"
/>
<span>{{ $msTranslate(placeholder) }}</span>
</div>
<div
class="popover-container"
v-show="showPopover"
>
<ion-input
class="form-input input"
ref="inputRef"
:value="modelValue"
:placeholder="$msTranslate(placeholder)"
:clear-input="true"
@ion-input="onChange($event.target.value)"
@keyup.enter="onEnterPress()"
@ion-blur="showPopover = false"
mode="ios"
/>
</div>
</div>

<div v-else>
<ion-icon
:icon="search"
slot="start"
class="icon"
/>
<ion-input
class="form-input input"
ref="inputRef"
:value="modelValue"
:placeholder="$msTranslate(placeholder)"
:clear-input="true"
@ion-input="onChange($event.target.value)"
@keyup.enter="onEnterPress()"
mode="ios"
/>
<!-- mode=ios to change the clear icon style -->
</div>
</div>
</template>

<script setup lang="ts">
import { Translatable } from '@lib/services';
import { IonIcon, IonInput } from '@ionic/vue';
import { search } from 'ionicons/icons';
import { ref } from 'vue';
import { ref, nextTick } from 'vue';

const props = defineProps<{
modelValue?: string;
placeholder?: Translatable;
asPopover?: boolean;
}>();

const inputRef = ref();
const showPopover = ref(false);

const emits = defineEmits<{
(e: 'change', value: string): void;
Expand All @@ -48,6 +82,12 @@ defineExpose({
selectText,
});

async function openPopover(): Promise<void> {
showPopover.value = true;
await nextTick();
await inputRef.value.$el.setFocus();
}

function setFocus(): void {
setTimeout(() => {
if (inputRef.value && inputRef.value.$el) {
Expand Down Expand Up @@ -99,4 +139,17 @@ function onChange(value: any): void {
color: var(--parsec-color-light-secondary-light);
}
}

.popover-container {
padding: 0.5rem 0;
display: flex;
flex-direction: column;
position: absolute;
width: 100%;
border: 1px solid var(--parsec-color-light-secondary-light);
background: var(--parsec-color-light-secondary-white);
border-radius: var(--parsec-radius-8);
margin-top: 0.5rem;
z-index: 12;
}
</style>
6 changes: 4 additions & 2 deletions src/views/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@
<ion-label class="title-h3">{{ $msTranslate('usage.components.inputs.msSearchInput.title') }}</ion-label>
<ms-search-input
placeholder="lib.components.msSearchInput.placeholder"
v-model="searchIInputExample"
v-model="searchInputExample"
id="searchInputExample"
:as-popover="true"
/>
{{ searchInputExample }}
</div>
<div class="example-divider-item">
<ion-label class="title-h3">{{ $msTranslate('usage.components.inputs.msPasswordInput.title') }}</ion-label>
Expand Down Expand Up @@ -515,7 +517,7 @@ const inputExample = ref('');
const msInputRef = ref();
const textareaExample = ref('');
const passwordInputExample = ref('');
const searchIInputExample = ref('');
const searchInputExample = ref('');
const msReportTheme = ref(MsReportTheme.Info);
const toastOffset = ref('0');
const toastManager = new ToastManager();
Expand Down