Skip to content

Commit ab84540

Browse files
Replace input form with NcTextField
Signed-off-by: julia.kirschenheuter <[email protected]>
1 parent bc1da2f commit ab84540

6 files changed

Lines changed: 76 additions & 70 deletions

File tree

core/src/views/ContactsMenu.vue

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@
2929
<Contacts :size="20" />
3030
</template>
3131
<div class="contactsmenu__menu">
32-
<label for="contactsmenu__menu__search">{{ t('core', 'Search contacts') }}</label>
33-
<input id="contactsmenu__menu__search"
34-
v-model="searchTerm"
35-
class="contactsmenu__menu__search"
36-
type="search"
37-
:placeholder="t('core', 'Search contacts …')"
38-
@input="onInputDebounced">
32+
<div class="contactsmenu__menu__input-wrapper">
33+
<NcTextField :value.sync="searchTerm"
34+
trailing-button-icon="close"
35+
ref="contactsMenuInput"
36+
:label="t('core', 'Search contacts')"
37+
:trailing-button-label="t('core','Reset search')"
38+
:show-trailing-button="searchTerm !== ''"
39+
:placeholder="t('core', 'Search contacts …')"
40+
id="contactsmenu__menu__search"
41+
class="contactsmenu__menu__search"
42+
@input="onInputDebounced"
43+
@trailing-button-click="onReset" />
44+
</div>
3945
<NcEmptyContent v-if="error" :name="t('core', 'Could not load your contacts')">
4046
<template #icon>
4147
<Magnify />
@@ -88,6 +94,7 @@ import { translate as t } from '@nextcloud/l10n'
8894
import Contact from '../components/ContactsMenu/Contact.vue'
8995
import logger from '../logger.js'
9096
import Nextcloud from '../mixins/Nextcloud.js'
97+
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
9198
9299
export default {
93100
name: 'ContactsMenu',
@@ -100,6 +107,7 @@ export default {
100107
NcEmptyContent,
101108
NcHeaderMenu,
102109
NcLoadingIcon,
110+
NcTextField,
103111
},
104112
105113
mixins: [Nextcloud],
@@ -152,43 +160,63 @@ export default {
152160
onInputDebounced: debounce(function() {
153161
this.getContacts(this.searchTerm)
154162
}, 500),
163+
164+
/**
165+
* Reset the search state
166+
*/
167+
onReset() {
168+
this.searchTerm = ''
169+
this.contacts = []
170+
this.focusInput()
171+
},
172+
173+
/**
174+
* Focus the search input on next tick
175+
*/
176+
focusInput() {
177+
this.$nextTick(() => {
178+
this.$refs.contactsMenuInput.focus()
179+
this.$refs.contactsMenuInput.select()
180+
})
181+
},
182+
155183
},
156184
}
157185
</script>
158186

159187
<style lang="scss" scoped>
160188
.contactsmenu {
189+
overflow-y: hidden;
190+
161191
&__menu {
162-
/* show 2.5 to 4.5 entries depending on the screen height */
163-
height: calc(100vh - 50px * 3);
164-
max-height: calc(50px * 6 + 2px + 26px);
165-
min-height: calc(50px * 3.5);
192+
display: flex;
193+
flex-direction: column;
194+
overflow: hidden;
195+
height: calc(50px * 6 + 2px + 26px);
196+
max-height: inherit;
166197
167198
label[for="contactsmenu__menu__search"] {
168199
font-weight: bold;
169200
font-size: 19px;
170201
margin-left: 13px;
171202
}
172203
204+
&__input-wrapper {
205+
padding: 10px;
206+
z-index: 2;
207+
top: 0;
208+
}
209+
173210
&__search {
174211
width: 100%;
175212
height: 34px;
176-
margin: 8px 0;
177-
178-
&:focus,
179-
&:focus-visible,
180-
&:active {
181-
border-color: 2px solid var(--color-main-text) !important;
182-
box-shadow: 0 0 0 2px var(--color-main-background) !important;
183-
}
213+
margin-top: 0!important;
184214
}
185215
186216
&__content {
187-
/* fixed max height of the parent container without the search input */
188-
height: calc(100vh - 50px * 3 - 60px);
189-
max-height: calc(50px * 5);
190-
min-height: calc(50px * 3.5 - 50px);
191217
overflow-y: auto;
218+
margin-top: 10px;
219+
flex: 1 1 auto;
192220
193221
&__footer {
194222
display: flex;

core/src/views/UnifiedSearch.vue

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,22 @@
3535

3636
<!-- Search form & filters wrapper -->
3737
<div class="unified-search__input-wrapper">
38-
<label for="unified-search__input">{{ ariaLabel }}</label>
3938
<div class="unified-search__input-row">
40-
<form class="unified-search__form"
41-
role="search"
42-
:class="{'icon-loading-small': isLoading}"
43-
@submit.prevent.stop="onInputEnter"
44-
@reset.prevent.stop="onReset">
45-
<!-- Search input -->
46-
<input id="unified-search__input"
47-
ref="input"
48-
v-model="query"
49-
class="unified-search__form-input"
50-
type="search"
51-
:class="{'unified-search__form-input--with-reset': !!query}"
52-
:placeholder="t('core', 'Search {types} …', { types: typesNames.join(', ') })"
53-
aria-describedby="unified-search-desc"
54-
@input="onInputDebounced"
55-
@keypress.enter.prevent.stop="onInputEnter">
56-
<p id="unified-search-desc" class="hidden-visually">
57-
{{ t('core', 'Search starts once you start typing and results may be reached with the arrow keys') }}
58-
</p>
59-
60-
<!-- Reset search button -->
61-
<input v-if="!!query && !isLoading"
62-
type="reset"
63-
class="unified-search__form-reset icon-close"
64-
:aria-label="t('core','Reset search')"
65-
value="">
66-
67-
<input v-if="!!query && !isLoading && !enableLiveSearch"
68-
type="submit"
69-
class="unified-search__form-submit icon-confirm"
70-
:aria-label="t('core','Start search')"
71-
value="">
72-
</form>
39+
<NcTextField :value.sync="query"
40+
trailing-button-icon="close"
41+
:label="ariaLabel"
42+
ref="input"
43+
:trailing-button-label="t('core','Reset search')"
44+
:show-trailing-button="query !== ''"
45+
aria-describedby="unified-search-desc"
46+
class="unified-search__form-input"
47+
:class="{'unified-search__form-input--with-reset': !!query}"
48+
:placeholder="t('core', 'Search {types} …', { types: typesNames.join(', ') })"
49+
@trailing-button-click="onReset"
50+
@input="onInputDebounced" />
51+
<p id="unified-search-desc" class="hidden-visually">
52+
{{ t('core', 'Search starts once you start typing and results may be reached with the arrow keys') }}
53+
</p>
7354

7455
<!-- Search filters -->
7556
<NcActions v-if="availableFilters.length > 1"
@@ -152,6 +133,7 @@ import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
152133
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
153134
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
154135
import NcHeaderMenu from '@nextcloud/vue/dist/Components/NcHeaderMenu.js'
136+
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
155137
156138
import Magnify from 'vue-material-design-icons/Magnify.vue'
157139
@@ -175,6 +157,7 @@ export default {
175157
NcHeaderMenu,
176158
SearchResult,
177159
SearchResultPlaceholders,
160+
NcTextField,
178161
},
179162
180163
data() {
@@ -738,7 +721,7 @@ export default {
738721
739722
$margin: 10px;
740723
$input-height: 34px;
741-
$input-padding: 6px;
724+
$input-padding: 10px;
742725
743726
.unified-search {
744727
&__input-wrapper {
@@ -778,6 +761,7 @@ $input-padding: 6px;
778761
779762
&__filters {
780763
margin: $margin 0 $margin math.div($margin, 2);
764+
padding-top: 5px;
781765
ul {
782766
display: inline-flex;
783767
justify-content: space-between;
@@ -820,12 +804,6 @@ $input-padding: 6px;
820804
&::-webkit-search-results-decoration {
821805
-webkit-appearance: none;
822806
}
823-
824-
// Ellipsis earlier if reset button is here
825-
.icon-loading-small &,
826-
&--with-reset {
827-
padding-right: $input-height;
828-
}
829807
}
830808
831809
&-reset, &-submit {

dist/core-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-unified-search.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-unified-search.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)