Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paragon
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
paragon
Commits
5ef4eb48
Commit
5ef4eb48
authored
Jun 06, 2017
by
Ari Rizzitano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial setup for dropdown component
parent
b530f2e6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
130 additions
and
0 deletions
+130
-0
src/Dropdown.js
+130
-0
No files found.
src/Dropdown.js
0 → 100644
View file @
5ef4eb48
import
React
from
'react'
;
import
ReactDOM
from
'react-dom'
;
import
classNames
from
'classnames'
;
const
classes
=
{
dropdown
:
'dropdown'
,
active
:
'active'
,
toggle
:
'btn dropdown-toggle'
,
screenreader
:
'sr-only'
,
show
:
'show'
,
menu
:
'dropdown-menu'
,
menuItem
:
'dropdown-item'
,
};
const
triggerKeys
=
{
openMenu
:
[
'ArrowDown'
,
'Space'
,
],
closeMenu
:
[
'Escape'
,
],
};
export
default
class
Dropdown
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
addEvents
=
this
.
addEvents
.
bind
(
this
);
this
.
handleDocumentClick
=
this
.
handleDocumentClick
.
bind
(
this
);
this
.
handleToggleKeyDown
=
this
.
handleToggleKeyDown
.
bind
(
this
);
this
.
removeEvents
=
this
.
removeEvents
.
bind
(
this
);
this
.
toggle
=
this
.
toggle
.
bind
(
this
);
this
.
state
=
{
open
:
false
};
}
componentWillUpdate
(
_
,
nextState
)
{
if
(
nextState
.
open
)
{
this
.
addEvents
();
}
else
{
this
.
removeEvents
();
}
}
componentDidUpdate
()
{
if
(
this
.
state
.
open
)
{
this
.
firstItem
.
focus
();
}
}
addEvents
()
{
document
.
addEventListener
(
'click'
,
this
.
handleDocumentClick
,
true
);
}
removeEvents
()
{
document
.
removeEventListener
(
'click'
,
this
.
handleDocumentClick
,
true
);
}
handleDocumentClick
(
e
)
{
const
container
=
ReactDOM
.
findDOMNode
(
this
);
if
(
container
.
contains
(
e
.
target
)
&&
container
!==
e
.
target
)
{
return
;
}
this
.
toggle
();
}
handleToggleKeyDown
(
e
)
{
if
(
!
this
.
state
.
open
&&
triggerKeys
.
openMenu
.
indexOf
(
e
.
key
)
>
-
1
)
{
this
.
toggle
();
}
else
if
(
this
.
state
.
open
&&
triggerKeys
.
closeMenu
.
indexOf
(
e
.
key
)
>
-
1
)
{
this
.
toggle
();
this
.
toggleElem
.
focus
();
}
}
toggle
()
{
this
.
setState
({
open
:
!
this
.
state
.
open
});
}
render
()
{
const
props
=
{
title
:
'Settings'
};
return
(
<
div
>
<
div
className
=
{
classNames
([
classes
.
dropdown
,
{[
classes
.
show
]:
this
.
state
.
open
}
])}
>
<
button
aria
-
expanded
=
{
this
.
state
.
open
}
aria
-
haspopup
=
"true"
className
=
{
classNames
([
classes
.
toggle
,
{[
classes
.
active
]:
this
.
state
.
open
}
])}
onClick
=
{
this
.
toggle
}
onKeyDown
=
{
this
.
handleToggleKeyDown
}
type
=
"button"
ref
=
{(
toggleElem
)
=>
{
this
.
toggleElem
=
toggleElem
;}}
>
{
props
.
title
}
<
/button
>
<
ul
aria
-
label
=
{
props
.
title
}
aria
-
hidden
=
{
!
this
.
state
.
open
}
className
=
{
classes
.
menu
}
role
=
"menu"
>
<
li
role
=
"none"
className
=
{
classes
.
menuItem
}
>
<
a
role
=
"menuitem"
href
=
"http://google.com"
ref
=
{(
firstItem
)
=>
{
this
.
firstItem
=
firstItem
;}}
>
Option
1
<
/a
>
<
/li
>
<
li
role
=
"none"
className
=
{
classes
.
menuItem
}
>
<
a
role
=
"menuitem"
href
=
"http://google.com"
>
Option
2
<
/a
>
<
/li
>
<
li
role
=
"none"
className
=
{
classes
.
menuItem
}
>
<
a
role
=
"menuitem"
href
=
"http://google.com"
>
Option
3
<
/a
>
<
/li
>
<
/ul
>
<
/div
>
<
/div
>
);
}
}
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