Skip to content

Commit

Permalink
oh-colorpicker: Fix command not sent when state null & style not acce…
Browse files Browse the repository at this point in the history
…pted & cosmetic error on missing defaultColor (#1989)

Fixes #1713.

- Fix command not sent when current Item state is null.
- Fix style can not be set.
- Fix a (cosmetic) error thrown when defaultColor has no value.

---------

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Sep 5, 2023
1 parent 5900864 commit 6ba9293
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<template>
<div v-if="!config.openIn" ref="container" style="width: 100%" />
<div v-else ref="swatch" :class="config.swatchClasses || ['elevation-4', 'elevation-hover-8', 'elevation-pressed-1', 'elevation-transition']" :style="{
width: (config.swatchSize) ? config.swatchSize + 'px' : '32px',
height: (config.swatchSize) ? config.swatchSize + 'px' : '32px',
borderRadius: (config.swatchBorderRadius) ? config.swatchBorderRadius + 'px' : '6px',
cursor: 'pointer'
}" />
<div :style="config.style">
<div v-if="!config.openIn" ref="container" style="width: 100%" />
<div v-else ref="swatch" :class="config.swatchClasses || ['elevation-4', 'elevation-hover-8', 'elevation-pressed-1', 'elevation-transition']" :style="{
width: (config.swatchSize) ? config.swatchSize + 'px' : '32px',
height: (config.swatchSize) ? config.swatchSize + 'px' : '32px',
borderRadius: (config.swatchBorderRadius) ? config.swatchBorderRadius + 'px' : '6px',
cursor: 'pointer'
}" />
</div>
</template>

<script>
Expand Down Expand Up @@ -46,7 +48,14 @@ export default {
color[2] = color[2] / 100
return color
}
return JSON.parse(this.config.defaultColor) || null
if (this.config.defaultColor) {
try {
return JSON.parse(this.config.defaultColor)
} catch {
return null
}
}
return null
}
},
watch: {
Expand Down Expand Up @@ -119,8 +128,8 @@ export default {
},
areHSBEqual (hsb1, hsb2) {
// for the purposes of NOT entering an endless loop, we consider transient non-HSB values to be equal
if (hsb1.length !== hsb2.length) return true
if (hsb1.length !== 3 || hsb2.length !== 3) return true
if (hsb1.length !== hsb2.length) return false
if (hsb1.length !== 3 || hsb2.length !== 3) return false
return (hsb1[0] === hsb2[0] && hsb1[1] === hsb2[1] && hsb1[2] === hsb2[2])
},
roundedHSB (state) {
Expand Down

0 comments on commit 6ba9293

Please sign in to comment.