Skip to content

Commit

Permalink
Render color picker on top when there is not enough space below (see j…
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Sep 11, 2019
1 parent 83e9e06 commit fe14ab5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ https://github.com/josdejong/jsoneditor

## not yet published, version 7.0.4

- Fixed #723: schema error popup not always fully visible.
- Fixed #723: schema error popup and color picker not always fully visible.
- Fixed wrong text color in search box when using JSONEditor in combination
with bootstrap. See #791. Thanks @dmitry-kulikov.
- Fixed react examples not working out of the box when cloning or downloading
Expand Down
10 changes: 9 additions & 1 deletion src/js/treemode.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,18 @@ treemode._setOptions = function (options) {
colorPicker: true,
onColorPicker: function (parent, color, onChange) {
if (VanillaPicker) {
// we'll render the color picker on top
// when there is not enough space below, and there is enough space above
const pickerHeight = 300; // estimated height of the color picker
const top = parent.getBoundingClientRect().top
const windowHeight = window.innerHeight

new VanillaPicker({
parent: parent,
color: color,
popup: 'bottom',
popup: ((windowHeight - top) < pickerHeight && top > pickerHeight)
? 'top'
: 'bottom',
onDone: function (color) {
const alpha = color.rgba[3]
const hex = (alpha === 1)
Expand Down

0 comments on commit fe14ab5

Please sign in to comment.