Skip to content

Commit f3813c6

Browse files
committed
Focus trap contacts menu with NcHeaderMenu port
Signed-off-by: Christopher Ng <chrng8@gmail.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
1 parent f7ff548 commit f3813c6

17 files changed

Lines changed: 235 additions & 220 deletions

File tree

core/css/server.css

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

core/css/server.css.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.

core/css/styles.css

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

core/css/styles.css.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.

core/css/styles.scss

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -893,160 +893,6 @@ span.ui-icon {
893893
margin: 3px 7px 30px 0;
894894
}
895895

896-
/* ---- CONTACTS MENU ---- */
897-
898-
#contactsmenu {
899-
.menutoggle {
900-
cursor: pointer;
901-
&:before {
902-
background-size: 20px 20px;
903-
background-repeat: no-repeat;
904-
background-position-x: 3px;
905-
background-position-y: 4px;
906-
padding: 14px;
907-
content: ' ';
908-
// Force white
909-
background-image: var(--original-icon-contacts-white);
910-
filter: var(--background-image-invert-if-bright);
911-
}
912-
913-
&:hover,
914-
&:focus,
915-
&:active {
916-
opacity: 1 !important;
917-
}
918-
}
919-
920-
#contactsmenu-menu {
921-
a {
922-
padding: 2px;
923-
924-
&:focus-visible {
925-
box-shadow: inset 0 0 0 2px var(--color-main-text) !important; // override rule in core/css/headers.scss #header a:focus-visible
926-
}
927-
}
928-
}
929-
}
930-
931-
#header .header-right > div#contactsmenu > .menu {
932-
/* show 2.5 to 4.5 entries depending on the screen height */
933-
height: calc(100vh - 50px * 3);
934-
max-height: calc(50px * 6 + 2px);
935-
min-height: calc(50px * 3.5);
936-
width: 350px;
937-
938-
.emptycontent {
939-
margin-top: 5vh !important;
940-
margin-bottom: 2vh;
941-
.icon-loading,
942-
.icon-search {
943-
display: inline-block;
944-
}
945-
}
946-
947-
.content {
948-
/* fixed max height of the parent container without the search input */
949-
height: calc(100vh - 50px * 3 - 50px);
950-
max-height: calc(50px * 5);
951-
min-height: calc(50px * 3.5 - 50px);
952-
overflow-y: auto;
953-
954-
.footer {
955-
text-align: center;
956-
957-
a {
958-
display: block;
959-
width: 100%;
960-
padding: 12px 0;
961-
opacity: .5;
962-
}
963-
}
964-
}
965-
966-
.contact {
967-
display: flex;
968-
position: relative;
969-
align-items: center;
970-
padding: 3px 3px 3px 10px;
971-
972-
.avatar {
973-
height: 32px;
974-
width: 32px;
975-
display: inline-block;
976-
}
977-
978-
.body {
979-
flex-grow: 1;
980-
padding-left: 8px;
981-
982-
div {
983-
position: relative;
984-
width: 100%;
985-
}
986-
987-
.full-name, .last-message {
988-
/* TODO: don't use fixed width */
989-
max-width: 204px;
990-
overflow: hidden;
991-
white-space: nowrap;
992-
text-overflow: ellipsis;
993-
}
994-
.last-message, .email-address {
995-
color: var(--color-text-maxcontrast);
996-
}
997-
}
998-
999-
.top-action, .second-action, .other-actions {
1000-
width: 16px;
1001-
height: 16px;
1002-
opacity: .5;
1003-
cursor: pointer;
1004-
1005-
&:not(button) {
1006-
padding: 14px;
1007-
}
1008-
img {
1009-
filter: var(--background-invert-if-dark);
1010-
}
1011-
1012-
&:hover,
1013-
&:active,
1014-
&:focus {
1015-
opacity: 1;
1016-
}
1017-
}
1018-
1019-
button.other-actions {
1020-
width: 44px;
1021-
1022-
&:focus {
1023-
border-color: transparent;
1024-
box-shadow: 0 0 0 2px var(--color-main-text);
1025-
}
1026-
1027-
&:focus-visible {
1028-
border-radius: var(--border-radius-pill);
1029-
}
1030-
}
1031-
1032-
/* actions menu */
1033-
.menu {
1034-
top: 47px;
1035-
margin-right: 13px;
1036-
}
1037-
.popovermenu::after {
1038-
right: 2px;
1039-
}
1040-
}
1041-
}
1042-
1043-
1044-
#contactsmenu-search {
1045-
width: calc(100% - 16px);
1046-
margin: 8px;
1047-
height: 34px;
1048-
}
1049-
1050896
/* ---- TOOLTIPS ---- */
1051897

1052898
.extra-data {

core/js/tests/specs/contactsmenuSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Contacts menu', function() {
3232
* @returns {Promise}
3333
*/
3434
function openMenu() {
35-
return menu._toggleVisibility(true);
35+
return menu.loadContacts();
3636
}
3737

3838
beforeEach(function(done) {

core/src/OC/contactsmenu.js

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ const ContactsMenuView = View.extend({
381381

382382
/**
383383
* @param {Object} options
384-
* @param {jQuery} options.el
385-
* @param {jQuery} options.trigger
384+
* @param {string} options.el
386385
* @class ContactsMenu
387386
* @memberOf OC
388387
*/
@@ -391,12 +390,9 @@ const ContactsMenu = function(options) {
391390
}
392391

393392
ContactsMenu.prototype = {
394-
/** @type {jQuery} */
393+
/** @type {string} */
395394
$el: undefined,
396395

397-
/** @type {jQuery} */
398-
_$trigger: undefined,
399-
400396
/** @type {ContactsMenuView} */
401397
_view: undefined,
402398

@@ -405,41 +401,19 @@ ContactsMenu.prototype = {
405401

406402
/**
407403
* @param {Object} options
408-
* @param {jQuery} options.el - the element to render the menu in
409-
* @param {jQuery} options.trigger - the element to click on to open the menu
404+
* @param {string} options.el - the selector of the element to render the menu in
410405
* @returns {undefined}
411406
*/
412407
initialize: function(options) {
413-
this.$el = options.el
414-
this._$trigger = options.trigger
408+
this.$el = $(options.el)
415409

416410
this._view = new ContactsMenuView({
417-
el: this.$el
411+
el: this.$el,
418412
})
413+
419414
this._view.on('search', function(searchTerm) {
420-
this._loadContacts(searchTerm)
415+
this.loadContacts(searchTerm)
421416
}, this)
422-
423-
OC.registerMenu(this._$trigger, this.$el, function() {
424-
this._toggleVisibility(true)
425-
}.bind(this), true)
426-
this.$el.on('beforeHide', function() {
427-
this._toggleVisibility(false)
428-
}.bind(this))
429-
},
430-
431-
/**
432-
* @private
433-
* @param {boolean} show
434-
* @returns {Promise}
435-
*/
436-
_toggleVisibility: function(show) {
437-
if (show) {
438-
return this._loadContacts()
439-
} else {
440-
this.$el.html('')
441-
return Promise.resolve()
442-
}
443417
},
444418

445419
/**
@@ -461,7 +435,7 @@ ContactsMenu.prototype = {
461435
* @param {string|undefined} searchTerm
462436
* @returns {undefined}
463437
*/
464-
_loadContacts: function(searchTerm) {
438+
loadContacts: function(searchTerm) {
465439
var self = this
466440

467441
if (!self._contactsPromise) {

core/src/components/ContactsMenu.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
33
*
44
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
5+
* @author Christopher Ng <chrng8@gmail.com>
56
* @author John Molakvoæ <skjnldsv@protonmail.com>
67
*
78
* @license AGPL-3.0-or-later
@@ -21,16 +22,20 @@
2122
*
2223
*/
2324

24-
import $ from 'jquery'
25-
import OC from '../OC'
25+
import Vue from 'vue'
26+
27+
import ContactsMenu from '../views/ContactsMenu.vue'
2628

2729
/**
2830
* @todo move to contacts menu code https://github.com/orgs/nextcloud/projects/31#card-21213129
2931
*/
3032
export const setUp = () => {
31-
// eslint-disable-next-line no-new
32-
new OC.ContactsMenu({
33-
el: $('#contactsmenu .menu'),
34-
trigger: $('#contactsmenu .menutoggle'),
35-
})
33+
const mountPoint = document.getElementById('contactsmenu')
34+
if (mountPoint) {
35+
// eslint-disable-next-line no-new
36+
new Vue({
37+
el: mountPoint,
38+
render: h => h(ContactsMenu),
39+
})
40+
}
3641
}

0 commit comments

Comments
 (0)