Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
49ff6369
Commit
49ff6369
authored
May 13, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split out dropdown base class
parent
cae5e9c8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
32 deletions
+57
-32
src/components/dropdown.js
src/components/dropdown.js
+57
-32
No files found.
src/components/dropdown.js
View file @
49ff6369
...
@@ -4,11 +4,56 @@ import { until } from 'lit-html/directives/until.js';
...
@@ -4,11 +4,56 @@ import { until } from 'lit-html/directives/until.js';
import
DOMNavigator
from
"
../dom-navigator
"
;
import
DOMNavigator
from
"
../dom-navigator
"
;
import
{
converse
}
from
"
@converse/headless/converse-core
"
;
import
{
converse
}
from
"
@converse/headless/converse-core
"
;
const
u
=
converse
.
env
.
utils
;
const
u
=
converse
.
env
.
utils
;
export
class
Dropdown
extends
CustomElement
{
export
class
BaseDropdown
extends
CustomElement
{
static
get
properties
()
{
return
{
''
:
{
type
:
Array
}
}
}
firstUpdated
()
{
this
.
menu
=
this
.
querySelector
(
'
.dropdown-menu
'
);
this
.
dropdown
=
this
.
firstElementChild
;
this
.
button
=
this
.
dropdown
.
querySelector
(
'
button
'
);
this
.
dropdown
.
addEventListener
(
'
click
'
,
ev
=>
this
.
toggleMenu
(
ev
));
this
.
dropdown
.
addEventListener
(
'
keyup
'
,
ev
=>
this
.
handleKeyUp
(
ev
));
document
.
addEventListener
(
'
click
'
,
ev
=>
!
this
.
contains
(
ev
.
target
)
&&
this
.
hideMenu
(
ev
));
}
hideMenu
()
{
u
.
removeClass
(
'
show
'
,
this
.
menu
);
this
.
button
.
setAttribute
(
'
aria-expanded
'
,
false
);
this
.
button
.
blur
();
}
showMenu
()
{
u
.
addClass
(
'
show
'
,
this
.
menu
);
this
.
button
.
setAttribute
(
'
aria-expanded
'
,
true
);
}
toggleMenu
()
{
if
(
u
.
hasClass
(
'
show
'
,
this
.
menu
))
{
this
.
hideMenu
();
}
else
{
this
.
showMenu
();
}
}
handleKeyUp
(
ev
)
{
if
(
ev
.
keyCode
===
converse
.
keycodes
.
ESCAPE
)
{
this
.
hideMenu
();
}
else
if
(
ev
.
keyCode
===
converse
.
keycodes
.
DOWN_ARROW
&&
!
this
.
navigator
.
enabled
)
{
this
.
enableArrowNavigation
(
ev
);
}
}
}
export
class
DropdownList
extends
BaseDropdown
{
static
get
properties
()
{
static
get
properties
()
{
return
{
return
{
...
@@ -29,13 +74,14 @@ export class Dropdown extends CustomElement {
...
@@ -29,13 +74,14 @@ export class Dropdown extends CustomElement {
`
;
`
;
}
}
hideMenu
()
{
super
.
hideMenu
();
this
.
navigator
.
disable
();
}
firstUpdated
()
{
firstUpdated
()
{
this
.
menu
=
this
.
querySelector
(
'
.dropdown-menu
'
);
super
.
firstUpdated
();
this
.
dropdown
=
this
.
firstElementChild
;
this
.
button
=
this
.
dropdown
.
querySelector
(
'
button
'
);
this
.
dropdown
.
addEventListener
(
'
click
'
,
ev
=>
this
.
toggleMenu
(
ev
));
this
.
dropdown
.
addEventListener
(
'
keyup
'
,
ev
=>
this
.
handleKeyUp
(
ev
));
document
.
addEventListener
(
'
click
'
,
ev
=>
!
this
.
contains
(
ev
.
target
)
&&
this
.
hideMenu
(
ev
));
this
.
initArrowNavigation
();
this
.
initArrowNavigation
();
}
}
...
@@ -58,33 +104,12 @@ export class Dropdown extends CustomElement {
...
@@ -58,33 +104,12 @@ export class Dropdown extends CustomElement {
this
.
navigator
.
select
(
this
.
menu
.
firstElementChild
);
this
.
navigator
.
select
(
this
.
menu
.
firstElementChild
);
}
}
hideMenu
()
{
u
.
removeClass
(
'
show
'
,
this
.
menu
);
this
.
navigator
.
disable
();
this
.
button
.
setAttribute
(
'
aria-expanded
'
,
false
);
this
.
button
.
blur
();
}
showMenu
()
{
u
.
addClass
(
'
show
'
,
this
.
menu
);
this
.
button
.
setAttribute
(
'
aria-expanded
'
,
true
);
}
toggleMenu
()
{
if
(
u
.
hasClass
(
'
show
'
,
this
.
menu
))
{
this
.
hideMenu
();
}
else
{
this
.
showMenu
();
}
}
handleKeyUp
(
ev
)
{
handleKeyUp
(
ev
)
{
if
(
ev
.
keyCode
===
converse
.
keycodes
.
ESCAPE
)
{
super
.
handleKeyUp
();
this
.
hideMenu
();
if
(
ev
.
keyCode
===
converse
.
keycodes
.
DOWN_ARROW
&&
!
this
.
navigator
.
enabled
)
{
}
else
if
(
ev
.
keyCode
===
converse
.
keycodes
.
DOWN_ARROW
&&
!
this
.
navigator
.
enabled
)
{
this
.
enableArrowNavigation
(
ev
);
this
.
enableArrowNavigation
(
ev
);
}
}
}
}
}
}
window
.
customElements
.
define
(
'
converse-dropdown
'
,
Dropdown
);
window
.
customElements
.
define
(
'
converse-dropdown
'
,
Dropdown
List
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment