Skip to content

Commit

Permalink
Merge pull request #112 from UoaWDCC/VPS-061/double-click-focusses-input
Browse files Browse the repository at this point in the history
VPS 061/Double click on speech box, focus on text input
  • Loading branch information
djos192 authored Aug 6, 2023
2 parents abe1e08 + 5062908 commit 90d0910
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from "react";
import React, { useContext, useEffect, useRef } from "react";
import {
FormControl,
InputLabel,
Expand All @@ -11,10 +11,11 @@ import FormatAlignLeftIcon from "@material-ui/icons/FormatAlignLeft";
import FormatAlignCenterIcon from "@material-ui/icons/FormatAlignCenter";
import FormatAlignRightIcon from "@material-ui/icons/FormatAlignRight";
import FormatAlignJustifyIcon from "@material-ui/icons/FormatAlignJustify";
import SceneContext from "../../../../../context/SceneContext";
import CustomInputLabelStyles from "../CustomPropertyInputStyles/CustomInputLabelStyles";
import SceneContext from "context/SceneContext";
import AuthoringToolContext from "context/AuthoringToolContext";

import styles from "../../../../../styling/CanvasSideBar.module.scss";
import styles from "styling/CanvasSideBar.module.scss";
import CustomInputLabelStyles from "../CustomPropertyInputStyles/CustomInputLabelStyles";
import useStyles from "./TextPropertiesComponent.styles";

const CustomInputLabel = CustomInputLabelStyles()(InputLabel);
Expand All @@ -31,7 +32,13 @@ export default function SpeechTextPropertiesComponent({
}) {
const textComponentStyles = useStyles();
const { updateComponentProperty } = useContext(SceneContext);
// const reference = React.createRef();

const { addPropertyRef } = useContext(AuthoringToolContext);
const textRef = useRef(null);

useEffect(() => {
addPropertyRef("text", textRef);
}, []);

return (
<>
Expand All @@ -40,6 +47,7 @@ export default function SpeechTextPropertiesComponent({
<OutlinedInput
className={textComponentStyles.textArea}
value={component.text}
inputRef={textRef}
fullWidth
multiline
rows={5}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from "react";
import React, { useContext, useEffect, useRef } from "react";
import {
FormControl,
InputLabel,
Expand All @@ -13,11 +13,13 @@ import FormatAlignLeftIcon from "@material-ui/icons/FormatAlignLeft";
import FormatAlignCenterIcon from "@material-ui/icons/FormatAlignCenter";
import FormatAlignRightIcon from "@material-ui/icons/FormatAlignRight";
import FormatAlignJustifyIcon from "@material-ui/icons/FormatAlignJustify";
import SceneContext from "../../../../../context/SceneContext";

import AuthoringToolContext from "context/AuthoringToolContext";
import SceneContext from "context/SceneContext";

import styles from "styling/CanvasSideBar.module.scss";
import CustomInputLabelStyles from "../CustomPropertyInputStyles/CustomInputLabelStyles";
import CustomCheckBoxStyles from "../CustomPropertyInputStyles/CustomCheckBoxStyles";

import styles from "../../../../../styling/CanvasSideBar.module.scss";
import useStyles from "./TextPropertiesComponent.styles";

const CustomInputLabel = CustomInputLabelStyles()(InputLabel);
Expand All @@ -32,7 +34,15 @@ const sizes = [6, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 30, 36, 42, 48, 60, 72];
export default function TextPropertiesComponent({ component, componentIndex }) {
const textComponentStyles = useStyles();
const { updateComponentProperty } = useContext(SceneContext);
// const reference = React.createRef();

const addPropertyRef = useContext(AuthoringToolContext)?.addPropertyRef;
const textRef = useRef(null);

useEffect(() => {
if (addPropertyRef) {
addPropertyRef("text", textRef);
}
}, []);

return (
<>
Expand All @@ -41,6 +51,7 @@ export default function TextPropertiesComponent({ component, componentIndex }) {
<OutlinedInput
className={textComponentStyles.textArea}
value={component.text}
inputRef={textRef}
fullWidth
multiline
rows={5}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from "react";
import React, { useState, useContext } from "react";
import AuthoringToolContext from "context/AuthoringToolContext";
import SpeechTextboxArrow from "components/SpeechboxArrow";
import { Typography } from "@material-ui/core";
import useStyles from "./components.styles";
Expand All @@ -19,7 +20,8 @@ export default function SpeechTextComponent({ id, onClick, component }) {
const { defaultComponentStyling, speechTextComponentStyles } =
useStyles(component);
const [speechTextboxArrowWidth, setArrowWidth] = useState(null);

const context = useContext(AuthoringToolContext);
const textRef = context?.propertiesRefs?.text;
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
<div
Expand All @@ -30,6 +32,7 @@ export default function SpeechTextComponent({ id, onClick, component }) {
minWidth: speechTextboxArrowWidth + 10, // speechbox slightly wider than arrow
}}
onClick={onClick}
onDoubleClick={() => textRef?.current?.focus()}
id={id}
>
<SpeechTextboxArrow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Typography } from "@material-ui/core";
import React from "react";
import React, { useContext } from "react";
import AuthoringToolContext from "context/AuthoringToolContext";
import useStyles from "./components.styles";
// import TextPropertiesComponent from "../CanvasSideBar/ComponentProperties/TextPropertiesComponent";

Expand All @@ -15,20 +16,17 @@ import useStyles from "./components.styles";
* />
*/
export default function TextComponent({ id, onClick, component }) {
const handleDoubleClick = () => {
const reference = document.querySelector("textarea");
reference.focus();
};

const styles = useStyles(component);
// const { updateComponentProperty } = useContext(SceneContext);

const context = useContext(AuthoringToolContext);
const textRef = context?.propertiesRefs?.text;

return (
<Typography
className={`${styles.defaultComponentStyling} ${styles.textComponentStyles}`}
id={id}
onClick={onClick}
onDoubleClick={handleDoubleClick}
onDoubleClick={() => textRef?.current?.focus()}
>
{component.text}
</Typography>
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/context/AuthoringToolContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function AuthoringToolContextProvider({ children }) {
const [shiftPressed, setShiftPressed] = useState(false);

const selectRef = useRef(select);
const [propertiesRefs, setPropertiesRefs] = useState({}); // stores refs of property inputs

function selectElement({ currentTarget }) {
const image = currentTarget.firstElementChild?.nodeName === "IMG";
Expand Down Expand Up @@ -45,6 +46,12 @@ export default function AuthoringToolContextProvider({ children }) {
}
}

function addPropertyRef(propertyName, propertyRef) {
setPropertiesRefs((current) => {
return { ...current, [propertyName]: propertyRef };
});
}

return (
<AuthoringToolContext.Provider
value={{
Expand All @@ -57,6 +64,8 @@ export default function AuthoringToolContextProvider({ children }) {
shiftPressed,
setShiftPressed,
deleteElement,
propertiesRefs,
addPropertyRef,
}}
>
{children}
Expand Down

0 comments on commit 90d0910

Please sign in to comment.