Skip to content

Commit

Permalink
make bg color selector more stable,
Browse files Browse the repository at this point in the history
doesn't close on click now anymore
  • Loading branch information
Simon-Laux authored and Jikstra committed Nov 25, 2019
1 parent 385d4c4 commit a6f837f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/renderer/components/dialogs/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ class BackgroundSelector extends React.Component {
constructor () {
super()
this.fileInput = React.createRef()
this.colorInput = React.createRef()
this.colorInput = document.getElementById('color-input') // located in index.html outside of react
this.colorInput.onchange = ev => this.onColor.bind(this)(ev)
}

componentWillUnmount () {
this.colorInput.onchange = null
}

render () {
Expand Down Expand Up @@ -420,12 +425,6 @@ class BackgroundSelector extends React.Component {
'background_old.jpg'
].map((elem) => <div onClick={this.onButton.bind(this, 'pimage')} style={{ backgroundImage: `url(../images/backgrounds/${elem})` }} key={elem} data-url={elem} />) }
</div>
<div hidden>
<input
type={'color'}
onChange={this.onColor.bind(this)}
ref={this.colorInput} /> // todo put this somewhere where it isn't closed by react rerender imidiately
</div>
</div>
)
}
Expand All @@ -449,7 +448,7 @@ class BackgroundSelector extends React.Component {
ipcRenderer.send('selectBackgroundImage', ev.target.dataset.url)
break
case 'color':
this.colorInput.current && this.colorInput.current.click()
this.colorInput && this.colorInput.click()
break
default:
/* ignore-console-log */
Expand Down
3 changes: 3 additions & 0 deletions static/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
<body>
<div id='root'></div>
<script type="text/javascript" src="bundle.js"></script>
<div hidden>
<input id='color-input' type='color'/>
</div>
</body>
</html>

0 comments on commit a6f837f

Please sign in to comment.