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
35d2bf83
Commit
35d2bf83
authored
Sep 20, 2017
by
Ari Rizzitano
Committed by
GitHub
Sep 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #33 from edx/ari/fix-dropdown
patch dropdown for bootstrap v4
parents
bdde7afe
e68a5c83
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
57 deletions
+59
-57
.storybook/__snapshots__/Storyshots.test.js.snap
+21
-33
src/Dropdown/Dropdown.scss
+10
-2
src/Dropdown/Dropdown.test.jsx
+3
-3
src/Dropdown/index.jsx
+25
-19
No files found.
.storybook/__snapshots__/Storyshots.test.js.snap
View file @
35d2bf83
...
@@ -91,7 +91,7 @@ exports[`Storyshots Dropdown basic usage 1`] = `
...
@@ -91,7 +91,7 @@ exports[`Storyshots Dropdown basic usage 1`] = `
<button
<button
aria-expanded={false}
aria-expanded={false}
aria-haspopup="true"
aria-haspopup="true"
className="
btn-borderless dropdown-toggle btn btn-secondary
"
className="
dropdown-toggle btn btn-light
"
onBlur={[Function]}
onBlur={[Function]}
onClick={[Function]}
onClick={[Function]}
onKeyDown={[Function]}
onKeyDown={[Function]}
...
@@ -99,49 +99,37 @@ exports[`Storyshots Dropdown basic usage 1`] = `
...
@@ -99,49 +99,37 @@ exports[`Storyshots Dropdown basic usage 1`] = `
>
>
Search Engines
Search Engines
</button>
</button>
<
ul
<
div
aria-hidden={true}
aria-hidden={true}
aria-label="Search Engines"
aria-label="Search Engines"
className="dropdown-menu"
className="dropdown-menu"
role="menu"
role="menu"
>
>
<
li
<
a
className="dropdown-item"
className="dropdown-item"
href="https://google.com"
onKeyDown={[Function]}
role="menuitem"
>
>
<a
Google
href="https://google.com"
</a>
onKeyDown={[Function]}
<a
role="menuitem"
tabIndex="-1"
>
Google
</a>
</li>
<li
className="dropdown-item"
className="dropdown-item"
href="https://duckduckgo.com"
onKeyDown={[Function]}
role="menuitem"
>
>
<a
DuckDuckGo
href="https://duckduckgo.com"
</a>
onKeyDown={[Function]}
<a
role="menuitem"
tabIndex="-1"
>
DuckDuckGo
</a>
</li>
<li
className="dropdown-item"
className="dropdown-item"
href="https://yahoo.com"
onKeyDown={[Function]}
role="menuitem"
>
>
<a
Yahoo
href="https://yahoo.com"
</a>
onKeyDown={[Function]}
</div>
role="menuitem"
tabIndex="-1"
>
Yahoo
</a>
</li>
</ul>
</div>
</div>
`;
`;
...
...
src/Dropdown/Dropdown.scss
View file @
35d2bf83
@import
"~bootstrap/scss/_dropdown"
;
@import
"~bootstrap/scss/_dropdown"
;
.btn-borderless
{
// Trying to patch this upstream, then this can
border
:
0
!
important
;
// be removed.
// https://github.com/twbs/bootstrap/pull/23990
.show
{
>
a
:focus
{
outline-width
:
2px
;
outline-style
:
solid
;
outline-color
:
Highlight
;
outline
:
-
webkit-focus-ring-color
auto
5px
;
}
}
}
src/Dropdown/Dropdown.test.jsx
View file @
35d2bf83
...
@@ -26,14 +26,14 @@ describe('<Dropdown />', () => {
...
@@ -26,14 +26,14 @@ describe('<Dropdown />', () => {
{
...
props
}
{
...
props
}
/>,
/>,
);
);
const
menu
=
wrapper
.
find
(
'
ul
'
);
const
menu
=
wrapper
.
find
(
'
.dropdown-menu
'
);
const
button
=
wrapper
.
find
(
'[type="button"]'
);
const
button
=
wrapper
.
find
(
'[type="button"]'
);
it
(
'with menu and toggle'
,
()
=>
{
it
(
'with menu and toggle'
,
()
=>
{
expect
(
button
.
exists
()).
toEqual
(
true
);
expect
(
button
.
exists
()).
toEqual
(
true
);
expect
(
menu
.
prop
(
'aria-label'
)).
toEqual
(
props
.
title
);
expect
(
menu
.
prop
(
'aria-label'
)).
toEqual
(
props
.
title
);
expect
(
menu
.
exists
()).
toEqual
(
true
);
expect
(
menu
.
exists
()).
toEqual
(
true
);
expect
(
menu
.
find
(
'
li
'
)).
toHaveLength
(
props
.
menuItems
.
length
);
expect
(
menu
.
find
(
'
a
'
)).
toHaveLength
(
props
.
menuItems
.
length
);
});
});
it
(
'with menu closed'
,
()
=>
{
it
(
'with menu closed'
,
()
=>
{
...
@@ -110,7 +110,7 @@ describe('<Dropdown />', () => {
...
@@ -110,7 +110,7 @@ describe('<Dropdown />', () => {
{
attachTo
:
div
},
{
attachTo
:
div
},
);
);
wrapper
.
find
(
'[type="button"]'
).
simulate
(
'click'
);
wrapper
.
find
(
'[type="button"]'
).
simulate
(
'click'
);
document
.
querySelector
(
'
ul
'
).
click
();
document
.
querySelector
(
'
.dropdown-menu
'
).
click
();
menuOpen
(
true
,
wrapper
);
menuOpen
(
true
,
wrapper
);
});
});
...
...
src/Dropdown/index.jsx
View file @
35d2bf83
...
@@ -98,19 +98,18 @@ class Dropdown extends React.Component {
...
@@ -98,19 +98,18 @@ class Dropdown extends React.Component {
generateMenuItems
(
menuItems
)
{
generateMenuItems
(
menuItems
)
{
return
menuItems
.
map
((
menuItem
,
i
)
=>
(
return
menuItems
.
map
((
menuItem
,
i
)
=>
(
<
li
className=
{
styles
[
'dropdown-item'
]
}
key=
{
i
}
>
<
a
<
a
className=
{
styles
[
'dropdown-item'
]
}
role=
"menuitem"
href=
{
menuItem
.
href
}
href=
{
menuItem
.
href
}
key=
{
i
}
onKeyDown=
{
this
.
handleMenuKeyDown
}
onKeyDown=
{
this
.
handleMenuKeyDown
}
ref=
{
(
item
)
=>
{
ref=
{
(
item
)
=>
{
this
.
menuItems
[
i
]
=
item
;
this
.
menuItems
[
i
]
=
item
;
}
}
}
}
tabIndex=
"-1"
role=
"menuitem"
>
>
{
menuItem
.
label
}
{
menuItem
.
label
}
</
a
>
</
a
>
</
li
>
));
));
}
}
...
@@ -127,36 +126,43 @@ class Dropdown extends React.Component {
...
@@ -127,36 +126,43 @@ class Dropdown extends React.Component {
<
Button
<
Button
aria
-
expanded=
{
this
.
state
.
open
}
aria
-
expanded=
{
this
.
state
.
open
}
aria
-
haspopup=
"true"
aria
-
haspopup=
"true"
buttonType=
"secondary"
buttonType=
{
this
.
props
.
buttonType
}
display=
{
this
.
props
.
title
}
display=
{
this
.
props
.
title
}
onClick=
{
this
.
toggle
}
onClick=
{
this
.
toggle
}
onKeyDown=
{
this
.
handleToggleKeyDown
}
onKeyDown=
{
this
.
handleToggleKeyDown
}
className=
{
[
className=
{
[
styles
[
'btn-borderless'
],
styles
[
'dropdown-toggle'
],
styles
[
'dropdown-toggle'
],
]
}
]
}
type=
"button"
type=
"button"
inputRef=
{
(
toggleElem
)
=>
{
this
.
toggleElem
=
toggleElem
;
}
}
inputRef=
{
(
toggleElem
)
=>
{
this
.
toggleElem
=
toggleElem
;
}
}
/>
/>
<
ul
<
div
aria
-
label=
{
this
.
props
.
title
}
aria
-
label=
{
this
.
props
.
title
}
aria
-
hidden=
{
!
this
.
state
.
open
}
aria
-
hidden=
{
!
this
.
state
.
open
}
className=
{
styles
[
'dropdown-menu'
]
}
className=
{
classNames
([
styles
[
'dropdown-menu'
],
{
[
styles
.
show
]:
this
.
state
.
open
},
])
}
role=
"menu"
role=
"menu"
>
>
{
menuItems
}
{
menuItems
}
</
ul
>
</
div
>
</
div
>
</
div
>
);
);
}
}
}
}
Dropdown
.
propTypes
=
{
Dropdown
.
propTypes
=
{
title
:
PropTypes
.
string
.
isRequired
,
buttonType
:
PropTypes
.
string
,
menuItems
:
PropTypes
.
arrayOf
(
PropTypes
.
shape
({
menuItems
:
PropTypes
.
arrayOf
(
PropTypes
.
shape
({
label
:
PropTypes
.
string
,
label
:
PropTypes
.
string
,
href
:
PropTypes
.
string
,
href
:
PropTypes
.
string
,
})).
isRequired
,
})).
isRequired
,
title
:
PropTypes
.
string
.
isRequired
,
};
Dropdown
.
defaultProps
=
{
buttonType
:
'light'
,
};
};
export
default
Dropdown
;
export
default
Dropdown
;
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