From 8c47f72792b41a775da390c0d54c5bdcd932647f Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Mon, 28 May 2018 16:49:56 +0200 Subject: [PATCH] fix: restore element name editing --- src/container/element-list/element-container.tsx | 10 ++++++---- src/container/element-list/element-list.tsx | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/container/element-list/element-container.tsx b/src/container/element-list/element-container.tsx index 21a1edce8..51d2353a3 100644 --- a/src/container/element-list/element-container.tsx +++ b/src/container/element-list/element-container.tsx @@ -1,3 +1,4 @@ +import * as AlvaUtil from '../../alva-util'; import * as Components from '../../components'; import { ElementContentContainer } from './element-content-container'; import * as MobxReact from 'mobx-react'; @@ -12,6 +13,8 @@ export interface ElementContainerProps { export class ElementContainer extends React.Component { public render(): JSX.Element | null { const { props } = this; + const open = + props.element.getOpen() || props.element.getDescendants().some(e => e.getSelected()); return ( { highlightPlaceholder={props.element.getPlaceholderHighlighted()} id={props.element.getId()} mayOpen={props.element.acceptsChildren()} - open={ - props.element.getOpen() || props.element.getDescendants().some(e => e.getSelected()) - } + open={open} + onChange={AlvaUtil.noop} title={props.element.getName()} > - {props.element.getOpen() + {open ? props.element .getContents() .map(content => ( diff --git a/src/container/element-list/element-list.tsx b/src/container/element-list/element-list.tsx index 59a2c058d..406103630 100644 --- a/src/container/element-list/element-list.tsx +++ b/src/container/element-list/element-list.tsx @@ -65,6 +65,15 @@ export class ElementList extends React.Component { } } + private handleChange(e: React.FormEvent): void { + const target = e.target as HTMLInputElement; + const changedElement = elementFromTarget(e.target, { sibling: false }); + + if (changedElement) { + changedElement.setName(target.value); + } + } + private handleClick(e: React.MouseEvent): void { const target = e.target as HTMLElement; const icon = above(target, `svg[${ElementAnchors.icon}]`); @@ -329,6 +338,7 @@ export class ElementList extends React.Component { data-drag-root {...{ [ElementAnchors.element]: rootElement.getId() }} onBlur={e => this.handleBlur(e)} + onChange={e => this.handleChange(e)} onClick={e => this.handleClick(e)} onContextMenu={e => this.handleContextMenu(e)} onDragEnd={e => this.handleDragEnd(e)}