Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: use ref instead of document.getElementById

Abdullah Atta452ff12071c6
diff --git a/packages/editor/src/toolbar/popups/color-picker.tsx b/packages/editor/src/toolbar/popups/color-picker.tsx
index 5d8fb93ac..16109c7d7 100644
--- a/packages/editor/src/toolbar/popups/color-picker.tsx
+++ b/packages/editor/src/toolbar/popups/color-picker.tsx
@@ -75,6 +75,7 @@ export function ColorPicker(props: ColorPickerProps) {
editor
} = props;
const ref = useRef<HTMLDivElement>(null);
+ const inputRef = useRef<HTMLInputElement>(null);
const [isPickerOpen, setIsPickerOpen] = useState(expanded || false);
const [currentColor, setCurrentColor] = useState<string>(
tinycolor(color || colors?.[0]).toHexString()
@@ -122,11 +123,8 @@ export function ColorPicker(props: ColorPickerProps) {
onChange={(color) => {
setCurrentColor(color);
onColorChange(color);
- (
- document.getElementById(
- "color-picker-input"
- ) as HTMLInputElement
- ).value = color.toUpperCase();
+ if (inputRef.current)
+ inputRef.current.value = color.toUpperCase();
}}
onTouchEnd={() => onChange(currentColor)}
onMouseUp={() => onChange(currentColor)}
@@ -139,10 +137,10 @@ export function ColorPicker(props: ColorPickerProps) {
}}
>
<Input
+ ref={inputRef}
variant={"clean"}
placeholder="#000000"
spellCheck={false}
- id="color-picker-input"
sx={{
my: 2,
p: 0,
@@ -157,11 +155,6 @@ export function ColorPicker(props: ColorPickerProps) {
maxLength={7}
onChange={(e) => {
const { value } = e.target;
- console.log(
- "onChange",
- value,
- tinycolor(value, { format: "hex" }).isValid()
- );
if (!value) return;
if (tinycolor(value, { format: "hex" }).isValid()) {
setCurrentColor(value);