Skip to content

Commit de83447

Browse files
committed
External link動きDebug
1 parent eba1946 commit de83447

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

browser/main/HomePage/ArticleTopBar.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,26 @@ export default class ArticleTopBar extends React.Component {
4242

4343
componentDidMount () {
4444
this.searchInput = ReactDOM.findDOMNode(this.refs.searchInput)
45+
this.linksButton = ReactDOM.findDOMNode(this.refs.links)
46+
this.showLinksDropdown = e => {
47+
e.preventDefault()
48+
e.stopPropagation()
49+
if (!this.state.isLinksDropdownOpen) {
50+
this.setState({isLinksDropdownOpen: true})
51+
}
52+
}
53+
this.linksButton.addEventListener('click', this.showLinksDropdown)
54+
this.hideLinksDropdown = e => {
55+
if (this.state.isLinksDropdownOpen) {
56+
this.setState({isLinksDropdownOpen: false})
57+
}
58+
}
59+
document.addEventListener('click', this.hideLinksDropdown)
4560
}
4661

4762
componentWillUnmount () {
48-
this.searchInput.removeEventListener('keydown', this.showTooltip)
49-
this.searchInput.removeEventListener('focus', this.showTooltip)
50-
this.searchInput.removeEventListener('blur', this.showTooltip)
63+
document.removeEventListener('click', this.hideLinksDropdown)
64+
this.linksButton.removeEventListener('click', this.showLinksDropdown())
5165
}
5266

5367
handleTooltipRequest (e) {
@@ -97,28 +111,6 @@ export default class ArticleTopBar extends React.Component {
97111
dispatch(toggleTutorial())
98112
}
99113

100-
handleLinksDropdownClick (e) {
101-
e.preventDefault()
102-
let linksButton = document.activeElement
103-
this.handleLinksDropdownClickHandler = e => {
104-
if (linksButton !== document.activeElement) {
105-
console.log('hide dropdown')
106-
document.removeEventListener('click', this.handleLinksDropdownClickHandler)
107-
this.setState({
108-
isLinksDropdownOpen: false
109-
})
110-
}
111-
}
112-
113-
if (!this.state.isLinksDropdownOpen) {
114-
document.removeEventListener('click', this.handleLinksDropdownClickHandler)
115-
document.addEventListener('click', this.handleLinksDropdownClickHandler)
116-
this.setState({
117-
isLinksDropdownOpen: true
118-
})
119-
}
120-
}
121-
122114
render () {
123115
let { status } = this.props
124116
return (
@@ -155,7 +147,7 @@ export default class ArticleTopBar extends React.Component {
155147
<div className='right'>
156148
<button onClick={e => this.handleTutorialButtonClick(e)}>?<span className='tooltip'>How to use</span>
157149
</button>
158-
<a className='linksBtn' onClick={e => this.handleLinksDropdownClick(e)} href>
150+
<a ref='links' className='linksBtn' href>
159151
<img src='../../resources/favicon-230x230.png' width='44' height='44'/>
160152
</a>
161153
{

0 commit comments

Comments
 (0)