diff --git a/v3/cypress/support/elements/component-elements.ts b/v3/cypress/support/elements/component-elements.ts index 0e8cd4f9f..236afd4ab 100644 --- a/v3/cypress/support/elements/component-elements.ts +++ b/v3/cypress/support/elements/component-elements.ts @@ -46,10 +46,11 @@ export const ComponentElements = { this.getComponentTitleBar(component, index).should(check, "focusTile") }, getComponentTitle(component, index = 0) { - return this.getComponentTile(component, index).find("[data-testid=editable-component-title]") + return this.getComponentTile(component, index).find("[data-testid=title-text]") }, changeComponentTitle(component: string, title: string, index = 0) { - this.getComponentTitle(component, index).click().find("[data-testid=title-text-input]").type(`${title}{enter}`) + this.getComponentTitle(component, index).click() + cy.get("[data-testid=title-text-input]").type(`${title}{enter}`) }, getInspectorPanel() { return cy.get("[data-testid=inspector-panel]") diff --git a/v3/cypress/support/elements/web-view-tile.ts b/v3/cypress/support/elements/web-view-tile.ts index 956b9e79e..0b436664f 100644 --- a/v3/cypress/support/elements/web-view-tile.ts +++ b/v3/cypress/support/elements/web-view-tile.ts @@ -43,8 +43,7 @@ export const WebViewTileElements = { sendAPITesterCommand(command: string, oldCommand?: string) { // Delete the old command if it's provided if (oldCommand) { - const deleteCommand = oldCommand.split("").reduce(cmd => `${cmd}{backspace}`, "") - WebViewTileElements.getIFrame().find(`.di-message-area`).type(deleteCommand) + WebViewTileElements.getIFrame().find(`.di-message-area`).clear() } WebViewTileElements.getIFrame().find(`.di-message-area`).type(command) WebViewTileElements.getIFrame().find(`.di-send-button`).click() diff --git a/v3/src/components/component-title-bar.scss b/v3/src/components/component-title-bar.scss index 04d7bbf3b..32265f414 100644 --- a/v3/src/components/component-title-bar.scss +++ b/v3/src/components/component-title-bar.scss @@ -106,7 +106,7 @@ .title-text-input { display: flex !important; justify-content: center !important; - height: calc($title-bar-height - 2px) !important; + height: calc($title-bar-height) !important; width: max-content; font-size: 14px !important; text-align: center !important; @@ -115,4 +115,5 @@ cursor: text; outline: none !important; border-radius: $border-radius-top-corners !important; + border: 2px solid #66afe9; } diff --git a/v3/src/components/component-title-bar.tsx b/v3/src/components/component-title-bar.tsx index c32f6086a..b37ba435b 100644 --- a/v3/src/components/component-title-bar.tsx +++ b/v3/src/components/component-title-bar.tsx @@ -1,5 +1,4 @@ -import { Button, CloseButton, Editable, EditableInput, EditablePreview, Flex } from "@chakra-ui/react" -import { useDndContext } from "@dnd-kit/core" +import { Button, CloseButton, Flex, Input } from "@chakra-ui/react" import { clsx } from "clsx" import { observer } from "mobx-react-lite" import React, { useState } from "react" @@ -17,8 +16,6 @@ export const ComponentTitleBar = observer(function ComponentTitleBar( const title = getTitle?.() || tile?.title || t("DG.AppController.createDataSet.name") const [isEditing, setIsEditing] = useState(false) const [editingTitle, setEditingTitle] = useState(title) - const { active } = useDndContext() - const dragging = !!active const tileId = tile?.id || "" const tileType = tile?.content.type const draggableOptions: IUseDraggableTile = { prefix: tileType || "tile", tileId, disabled: isEditing } @@ -36,10 +33,6 @@ export const ComponentTitleBar = observer(function ComponentTitleBar( } } - const handleChange = (nextValue: string) => { - setEditingTitle(nextValue) - } - const handleSubmit = (nextValue: string) => { if (onHandleTitleChange) { onHandleTitleChange(nextValue) @@ -56,17 +49,38 @@ export const ComponentTitleBar = observer(function ComponentTitleBar( setIsEditing(false) } + const handleTitleClick = () => { + setIsEditing(true) + setEditingTitle(title) + } + + const handleInputKeyDown = (e: React.KeyboardEvent) => { + const { key } = e + e.stopPropagation() + switch (key) { + case "Escape": + handleCancel(title) + break + case "Enter": + case "Tab": + handleSubmit(editingTitle) + break + } + } + return ( {children} - setIsEditing(true)} onSubmit={handleSubmit} - onChange={handleChange} onCancel={handleCancel} data-testid="editable-component-title" - > - - - +
+ {isEditing + ? setEditingTitle(e.target.value)} onBlur={() => handleSubmit(editingTitle)} + onFocus={(e) => e.target.select()} onKeyDown={handleInputKeyDown} + /> + :
{title}
+ } +