Skip to content

Commit

Permalink
Replace input form with NcTextField
Browse files Browse the repository at this point in the history
Signed-off-by: julia.kirschenheuter <[email protected]>
  • Loading branch information
JuliaKirschenheuter committed Nov 22, 2023
1 parent bc1da2f commit c20c3ce
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 70 deletions.
73 changes: 50 additions & 23 deletions core/src/views/ContactsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
<Contacts :size="20" />
</template>
<div class="contactsmenu__menu">
<label for="contactsmenu__menu__search">{{ t('core', 'Search contacts') }}</label>
<input id="contactsmenu__menu__search"
v-model="searchTerm"
class="contactsmenu__menu__search"
type="search"
:placeholder="t('core', 'Search contacts …')"
@input="onInputDebounced">
<div class="contactsmenu__menu__input-wrapper">
<NcTextField :value.sync="searchTerm"
trailing-button-icon="close"
ref="contactsMenuInput"
:label="t('core', 'Search contacts')"
:trailing-button-label="t('core','Reset search')"
:show-trailing-button="searchTerm !== ''"
:placeholder="t('core', 'Search contacts …')"
class="contactsmenu__menu__search"
@input="onInputDebounced"
@trailing-button-click="onReset" />
</div>
<NcEmptyContent v-if="error" :name="t('core', 'Could not load your contacts')">
<template #icon>
<Magnify />
Expand Down Expand Up @@ -88,6 +93,7 @@ import { translate as t } from '@nextcloud/l10n'
import Contact from '../components/ContactsMenu/Contact.vue'
import logger from '../logger.js'
import Nextcloud from '../mixins/Nextcloud.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'

export default {
name: 'ContactsMenu',
Expand All @@ -100,6 +106,7 @@ export default {
NcEmptyContent,
NcHeaderMenu,
NcLoadingIcon,
NcTextField,
},

mixins: [Nextcloud],
Expand Down Expand Up @@ -152,43 +159,63 @@ export default {
onInputDebounced: debounce(function() {
this.getContacts(this.searchTerm)
}, 500),

/**
* Reset the search state
*/
onReset() {
this.searchTerm = ''
this.contacts = []
this.focusInput()
},

/**
* Focus the search input on next tick
*/
focusInput() {
this.$nextTick(() => {
this.$refs.contactsMenuInput.focus()
this.$refs.contactsMenuInput.select()
})
},

},
}
</script>

<style lang="scss" scoped>
.contactsmenu {
overflow-y: hidden;

&__menu {
/* show 2.5 to 4.5 entries depending on the screen height */
height: calc(100vh - 50px * 3);
max-height: calc(50px * 6 + 2px + 26px);
min-height: calc(50px * 3.5);
display: flex;
flex-direction: column;
overflow: hidden;
height: calc(50px * 6);
max-height: inherit;

label[for="contactsmenu__menu__search"] {
font-weight: bold;
font-size: 19px;
margin-left: 13px;
}

&__input-wrapper {
padding: 10px;
z-index: 2;
top: 0;
}

Check warning on line 208 in core/src/views/ContactsMenu.vue

View check run for this annotation

Codecov / codecov/patch

core/src/views/ContactsMenu.vue#L208

Added line #L208 was not covered by tests
&__search {
width: 100%;
height: 34px;
margin: 8px 0;

&:focus,
&:focus-visible,
&:active {
border-color: 2px solid var(--color-main-text) !important;
box-shadow: 0 0 0 2px var(--color-main-background) !important;
}
margin-top: 0!important;
}

&__content {
/* fixed max height of the parent container without the search input */
height: calc(100vh - 50px * 3 - 60px);
max-height: calc(50px * 5);
min-height: calc(50px * 3.5 - 50px);
overflow-y: auto;
margin-top: 10px;
flex: 1 1 auto;

Check warning on line 218 in core/src/views/ContactsMenu.vue

View check run for this annotation

Codecov / codecov/patch

core/src/views/ContactsMenu.vue#L217-L218

Added lines #L217 - L218 were not covered by tests

&__footer {
display: flex;
Expand Down
60 changes: 19 additions & 41 deletions core/src/views/UnifiedSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,22 @@

<!-- Search form & filters wrapper -->
<div class="unified-search__input-wrapper">
<label for="unified-search__input">{{ ariaLabel }}</label>
<div class="unified-search__input-row">
<form class="unified-search__form"
role="search"
:class="{'icon-loading-small': isLoading}"
@submit.prevent.stop="onInputEnter"
@reset.prevent.stop="onReset">
<!-- Search input -->
<input id="unified-search__input"
ref="input"
v-model="query"
class="unified-search__form-input"
type="search"
:class="{'unified-search__form-input--with-reset': !!query}"
:placeholder="t('core', 'Search {types} …', { types: typesNames.join(', ') })"
aria-describedby="unified-search-desc"
@input="onInputDebounced"
@keypress.enter.prevent.stop="onInputEnter">
<p id="unified-search-desc" class="hidden-visually">
{{ t('core', 'Search starts once you start typing and results may be reached with the arrow keys') }}
</p>

<!-- Reset search button -->
<input v-if="!!query && !isLoading"
type="reset"
class="unified-search__form-reset icon-close"
:aria-label="t('core','Reset search')"
value="">

<input v-if="!!query && !isLoading && !enableLiveSearch"
type="submit"
class="unified-search__form-submit icon-confirm"
:aria-label="t('core','Start search')"
value="">
</form>
<NcTextField :value.sync="query"
trailing-button-icon="close"
:label="ariaLabel"
ref="input"
:trailing-button-label="t('core','Reset search')"
:show-trailing-button="query !== ''"
aria-describedby="unified-search-desc"
class="unified-search__form-input"
:class="{'unified-search__form-input--with-reset': !!query}"
:placeholder="t('core', 'Search {types} …', { types: typesNames.join(', ') })"
@trailing-button-click="onReset"
@input="onInputDebounced" />
<p id="unified-search-desc" class="hidden-visually">
{{ t('core', 'Search starts once you start typing and results may be reached with the arrow keys') }}
</p>

<!-- Search filters -->
<NcActions v-if="availableFilters.length > 1"
Expand Down Expand Up @@ -152,6 +133,7 @@ import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import NcHeaderMenu from '@nextcloud/vue/dist/Components/NcHeaderMenu.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'

import Magnify from 'vue-material-design-icons/Magnify.vue'

Expand All @@ -175,6 +157,7 @@ export default {
NcHeaderMenu,
SearchResult,
SearchResultPlaceholders,
NcTextField,
},

data() {
Expand Down Expand Up @@ -738,7 +721,7 @@ export default {

$margin: 10px;
$input-height: 34px;
$input-padding: 6px;
$input-padding: 10px;

.unified-search {
&__input-wrapper {
Expand Down Expand Up @@ -778,6 +761,7 @@ $input-padding: 6px;

&__filters {
margin: $margin 0 $margin math.div($margin, 2);
padding-top: 5px;
ul {
display: inline-flex;
justify-content: space-between;
Expand Down Expand Up @@ -820,12 +804,6 @@ $input-padding: 6px;
&::-webkit-search-results-decoration {
-webkit-appearance: none;
}

// Ellipsis earlier if reset button is here
.icon-loading-small &,
&--with-reset {
padding-right: $input-height;
}
}

&-reset, &-submit {
Expand Down
4 changes: 2 additions & 2 deletions dist/core-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/core-unified-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-unified-search.js.map

Large diffs are not rendered by default.

0 comments on commit c20c3ce

Please sign in to comment.