Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mastofe
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Haelwenn
mastofe
Commits
5ff733b6
Commit
5ff733b6
authored
Sep 11, 2018
by
Thibaut Girka
Committed by
ThibG
Sep 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only focus first item of dropdown if it was opened via keyboard
parent
cf142e85
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
11 deletions
+19
-11
app/javascript/flavours/glitch/actions/dropdown_menu.js
app/javascript/flavours/glitch/actions/dropdown_menu.js
+2
-2
app/javascript/flavours/glitch/components/dropdown_menu.js
app/javascript/flavours/glitch/components/dropdown_menu.js
+12
-5
app/javascript/flavours/glitch/containers/dropdown_menu_container.js
...ipt/flavours/glitch/containers/dropdown_menu_container.js
+3
-2
app/javascript/flavours/glitch/reducers/dropdown_menu.js
app/javascript/flavours/glitch/reducers/dropdown_menu.js
+2
-2
No files found.
app/javascript/flavours/glitch/actions/dropdown_menu.js
View file @
5ff733b6
export
const
DROPDOWN_MENU_OPEN
=
'
DROPDOWN_MENU_OPEN
'
;
export
const
DROPDOWN_MENU_CLOSE
=
'
DROPDOWN_MENU_CLOSE
'
;
export
function
openDropdownMenu
(
id
,
placement
)
{
return
{
type
:
DROPDOWN_MENU_OPEN
,
id
,
placement
};
export
function
openDropdownMenu
(
id
,
placement
,
keyboard
)
{
return
{
type
:
DROPDOWN_MENU_OPEN
,
id
,
placement
,
keyboard
};
}
export
function
closeDropdownMenu
(
id
)
{
...
...
app/javascript/flavours/glitch/components/dropdown_menu.js
View file @
5ff733b6
...
...
@@ -23,6 +23,7 @@ class DropdownMenu extends React.PureComponent {
placement
:
PropTypes
.
string
,
arrowOffsetLeft
:
PropTypes
.
string
,
arrowOffsetTop
:
PropTypes
.
string
,
openedViaKeyboard
:
PropTypes
.
bool
,
};
static
defaultProps
=
{
...
...
@@ -43,7 +44,7 @@ class DropdownMenu extends React.PureComponent {
componentDidMount
()
{
document
.
addEventListener
(
'
click
'
,
this
.
handleDocumentClick
,
false
);
document
.
addEventListener
(
'
touchend
'
,
this
.
handleDocumentClick
,
listenerOptions
);
if
(
this
.
focusedItem
)
this
.
focusedItem
.
focus
();
if
(
this
.
focusedItem
&&
this
.
props
.
openedviaKeyBoard
)
this
.
focusedItem
.
focus
();
this
.
setState
({
mounted
:
true
});
}
...
...
@@ -170,6 +171,7 @@ export default class Dropdown extends React.PureComponent {
onClose
:
PropTypes
.
func
.
isRequired
,
dropdownPlacement
:
PropTypes
.
string
,
openDropdownId
:
PropTypes
.
number
,
openedViaKeyboard
:
PropTypes
.
bool
,
};
static
defaultProps
=
{
...
...
@@ -180,14 +182,14 @@ export default class Dropdown extends React.PureComponent {
id
:
id
++
,
};
handleClick
=
({
target
})
=>
{
handleClick
=
({
target
,
type
})
=>
{
if
(
this
.
state
.
id
===
this
.
props
.
openDropdownId
)
{
this
.
handleClose
();
}
else
{
const
{
top
}
=
target
.
getBoundingClientRect
();
const
placement
=
top
*
2
<
innerHeight
?
'
bottom
'
:
'
top
'
;
this
.
props
.
onOpen
(
this
.
state
.
id
,
this
.
handleItemClick
,
placement
);
this
.
props
.
onOpen
(
this
.
state
.
id
,
this
.
handleItemClick
,
placement
,
type
!==
'
click
'
);
}
}
...
...
@@ -197,6 +199,11 @@ export default class Dropdown extends React.PureComponent {
handleKeyDown
=
e
=>
{
switch
(
e
.
key
)
{
case
'
'
:
case
'
Enter
'
:
this
.
handleClick
(
e
);
e
.
preventDefault
();
break
;
case
'
Escape
'
:
this
.
handleClose
();
break
;
...
...
@@ -232,7 +239,7 @@ export default class Dropdown extends React.PureComponent {
}
render
()
{
const
{
icon
,
items
,
size
,
ariaLabel
,
disabled
,
dropdownPlacement
,
openDropdownId
}
=
this
.
props
;
const
{
icon
,
items
,
size
,
ariaLabel
,
disabled
,
dropdownPlacement
,
openDropdownId
,
openedViaKeyboard
}
=
this
.
props
;
const
open
=
this
.
state
.
id
===
openDropdownId
;
return
(
...
...
@@ -248,7 +255,7 @@ export default class Dropdown extends React.PureComponent {
/
>
<
Overlay
show
=
{
open
}
placement
=
{
dropdownPlacement
}
target
=
{
this
.
findTarget
}
>
<
DropdownMenu
items
=
{
items
}
onClose
=
{
this
.
handleClose
}
/
>
<
DropdownMenu
items
=
{
items
}
onClose
=
{
this
.
handleClose
}
openedViaKeyboard
=
{
openedViaKeyboard
}
/
>
<
/Overlay
>
<
/div
>
);
...
...
app/javascript/flavours/glitch/containers/dropdown_menu_container.js
View file @
5ff733b6
...
...
@@ -8,10 +8,11 @@ const mapStateToProps = state => ({
isModalOpen
:
state
.
get
(
'
modal
'
).
modalType
===
'
ACTIONS
'
,
dropdownPlacement
:
state
.
getIn
([
'
dropdown_menu
'
,
'
placement
'
]),
openDropdownId
:
state
.
getIn
([
'
dropdown_menu
'
,
'
openId
'
]),
openedViaKeyboard
:
state
.
getIn
([
'
dropdown_menu
'
,
'
keyboard
'
]),
});
const
mapDispatchToProps
=
(
dispatch
,
{
status
,
items
})
=>
({
onOpen
(
id
,
onItemClick
,
dropdownPlacement
)
{
onOpen
(
id
,
onItemClick
,
dropdownPlacement
,
keyboard
)
{
dispatch
(
isUserTouching
()
?
openModal
(
'
ACTIONS
'
,
{
status
,
actions
:
items
.
map
(
...
...
@@ -21,7 +22,7 @@ const mapDispatchToProps = (dispatch, { status, items }) => ({
onClick
:
item
.
action
?
((
e
)
=>
{
return
onItemClick
(
i
,
e
)
})
:
null
,
}
:
null
),
})
:
openDropdownMenu
(
id
,
dropdownPlacement
));
})
:
openDropdownMenu
(
id
,
dropdownPlacement
,
keyboard
));
},
onClose
(
id
)
{
dispatch
(
closeModal
());
...
...
app/javascript/flavours/glitch/reducers/dropdown_menu.js
View file @
5ff733b6
...
...
@@ -4,12 +4,12 @@ import {
DROPDOWN_MENU_CLOSE
,
}
from
'
../actions/dropdown_menu
'
;
const
initialState
=
Immutable
.
Map
({
openId
:
null
,
placement
:
null
});
const
initialState
=
Immutable
.
Map
({
openId
:
null
,
placement
:
null
,
keyboard
:
false
});
export
default
function
dropdownMenu
(
state
=
initialState
,
action
)
{
switch
(
action
.
type
)
{
case
DROPDOWN_MENU_OPEN
:
return
state
.
merge
({
openId
:
action
.
id
,
placement
:
action
.
placement
});
return
state
.
merge
({
openId
:
action
.
id
,
placement
:
action
.
placement
,
keyboard
:
action
.
keyboard
});
case
DROPDOWN_MENU_CLOSE
:
return
state
.
get
(
'
openId
'
)
===
action
.
id
?
state
.
set
(
'
openId
'
,
null
)
:
state
;
default
:
...
...
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