Skip to content

Commit 9dbb023

Browse files
committed
[B] Ensure color input can render in drawer
1 parent 4d33cff commit 9dbb023

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

client/src/backend/components/hero/Builder/forms/JournalDescription.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ function JournalDescription({
124124
altTextName="attributes[logoAltText]"
125125
altTextLabel={t("journals.forms.logo_alt_label")}
126126
/>
127-
<Form.TextInput
127+
<Form.ColorInput
128128
label={t("hero.background_color")}
129129
name="attributes[heroBackgroundColor]"
130-
placeholder="#52e3ac"
130+
defaultValue="#52e3ac"
131131
instructions={t("hero.background_color_instructions")}
132+
container=".drawer--backend"
132133
wide
133134
/>
134135
<Form.TextArea

client/src/global/components/form/ColorInput/ColorInput.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { useId, useEffect, useRef } from "react";
2+
import PropTypes from "prop-types";
23
import Coloris from "@melloware/coloris";
34
import setter from "../setter";
45
import * as Styled from "./styles";
56

6-
function ColorInput({ defaultValue, ...props }) {
7+
function ColorInput({ defaultValue, container, ...props }) {
78
const id = useId();
89
const inputRef = useRef();
910
const colorRef = useRef(props.value || defaultValue);
1011

1112
const inputId = `color-input-${id}`;
1213

1314
useEffect(() => {
14-
Coloris.init();
15+
Coloris.init({ parent: container });
1516

1617
const setColor = event => {
1718
const isTarget = event.detail.currentEl.id === inputId;
@@ -21,7 +22,7 @@ function ColorInput({ defaultValue, ...props }) {
2122
document.addEventListener("coloris:pick", setColor);
2223

2324
return () => document.removeEventListener("coloris:pick", setColor);
24-
}, [inputId, props]);
25+
}, [inputId, container, props]);
2526

2627
useEffect(() => {
2728
const onClose = () => {
@@ -38,14 +39,15 @@ function ColorInput({ defaultValue, ...props }) {
3839
themeMode: "dark",
3940
clearButton: true,
4041
defaultColor: defaultValue,
41-
margin: 5
42+
margin: 5,
43+
parent: container
4244
});
4345

4446
inputEl.addEventListener("close", onClose);
4547

4648
return () => inputEl.removeEventListener("close", onClose);
4749
}
48-
}, [inputRef, defaultValue, colorRef, props]);
50+
}, [inputRef, defaultValue, colorRef, container, props]);
4951

5052
return (
5153
<Styled.ColorInput
@@ -60,6 +62,14 @@ function ColorInput({ defaultValue, ...props }) {
6062
);
6163
}
6264

65+
ColorInput.propTypes = {
66+
defaultValue: PropTypes.string.isRequired,
67+
// By default the color picker renders as a dialog in <body>.
68+
// Pass a selector if rendering in a focus trap.
69+
container: PropTypes.string
70+
// See BaseInput for remaining propTypes
71+
};
72+
6373
export default setter(ColorInput);
6474

6575
ColorInput.displayName = "Form.ColorInput";

0 commit comments

Comments
 (0)