Skip to content

Commit

Permalink
fix(NcColorPicker): close popover on submit event
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 27, 2024
1 parent 7e601ad commit 1bf28f7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 54 deletions.
107 changes: 55 additions & 52 deletions src/components/NcColorPicker/NcColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default {
<template>
<div class="container1">
<NcButton @click="open = !open"> Click Me </NcButton>
<NcColorPicker :model-value="color" @update:model-value="updateColor" :shown.sync="open" @submit="open = false" v-slot="{ attrs }">
<NcColorPicker :model-value="color" @update:model-value="updateColor" :shown.sync="open" v-slot="{ attrs }">
<div v-bind="attrs" :style="{'background-color': color}" class="color1" />
</NcColorPicker>
</div>
Expand Down Expand Up @@ -150,57 +150,59 @@ export default {
<template #trigger="slotProps">
<slot v-bind="slotProps" />
</template>
<div role="dialog"
class="color-picker"
aria-modal="true"
:aria-label="t('Color picker')"
:class="{ 'color-picker--advanced-fields': advanced && advancedFields }">
<Transition name="slide" mode="out-in">
<div v-if="!advanced" class="color-picker__simple">
<label v-for="({ color, name }, index) in normalizedPalette"
:key="index"
:style="{ backgroundColor: color }"
class="color-picker__simple-color-circle"
:class="{ 'color-picker__simple-color-circle--active' : color === currentColor }">
<Check v-if="color === currentColor" :size="20" :fill-color="contrastColor" />
<input type="radio"
class="hidden-visually"
:aria-label="name"
:name="`color-picker-${uid}`"
:checked="color === currentColor"
@click="pickColor(color)">
</label>
<template #default="slotProps">
<div role="dialog"
class="color-picker"
aria-modal="true"
:aria-label="t('Color picker')"
:class="{ 'color-picker--advanced-fields': advanced && advancedFields }">
<Transition name="slide" mode="out-in">
<div v-if="!advanced" class="color-picker__simple">
<label v-for="({ color, name }, index) in normalizedPalette"
:key="index"
:style="{ backgroundColor: color }"
class="color-picker__simple-color-circle"
:class="{ 'color-picker__simple-color-circle--active' : color === currentColor }">
<Check v-if="color === currentColor" :size="20" :fill-color="contrastColor" />
<input type="radio"
class="hidden-visually"
:aria-label="name"
:name="`color-picker-${uid}`"
:checked="color === currentColor"
@click="pickColor(color)">
</label>
</div>
<Chrome v-else
v-model="currentColor"
class="color-picker__advanced"
:disable-alpha="true"
:disable-fields="!advancedFields"
@input="pickColor" />
</Transition>
<div v-if="!paletteOnly" class="color-picker__navigation">
<NcButton v-if="advanced"
type="tertiary"
:aria-label="ariaBack"
@click="handleBack">
<template #icon>
<ArrowLeft :size="20" />
</template>
</NcButton>
<NcButton v-else
type="tertiary"
:aria-label="ariaMore"
@click="handleMoreSettings">
<template #icon>
<DotsHorizontal :size="20" />
</template>
</NcButton>
<NcButton type="primary"
@click="handleConfirm(slotProps.hide)">
{{ t('Choose') }}
</NcButton>
</div>
<Chrome v-else
v-model="currentColor"
class="color-picker__advanced"
:disable-alpha="true"
:disable-fields="!advancedFields"
@input="pickColor" />
</Transition>
<div v-if="!paletteOnly" class="color-picker__navigation">
<NcButton v-if="advanced"
type="tertiary"
:aria-label="ariaBack"
@click="handleBack">
<template #icon>
<ArrowLeft :size="20" />
</template>
</NcButton>
<NcButton v-else
type="tertiary"
:aria-label="ariaMore"
@click="handleMoreSettings">
<template #icon>
<DotsHorizontal :size="20" />
</template>
</NcButton>
<NcButton type="primary"
@click="handleConfirm">
{{ t('Choose') }}
</NcButton>
</div>
</div>
</template>
</NcPopover>
</template>

Expand Down Expand Up @@ -363,13 +365,14 @@ export default {

/**
* Submit a picked colour and close picker
* @param {Function} hideCallback callback to close popover
*/
handleConfirm() {
handleConfirm(hideCallback) {
/**
* Emits a hexadecimal string e.g. '#ffffff'
*/
this.$emit('submit', this.currentColor)
this.handleClose()
hideCallback()

this.advanced = false
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/NcPopover/NcPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ See: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
</NcPopoverTriggerProvider>

<!-- This will be the content of the popover -->
<template #popper>
<slot />
<template #popper="slotProps">
<slot name="default" v-bind="slotProps" />
</template>
</Dropdown>
</template>
Expand Down

0 comments on commit 1bf28f7

Please sign in to comment.