From f98c32d1eb1c5d3a1970ffdde12f9c6fbc7cdf87 Mon Sep 17 00:00:00 2001 From: kunzheng <58841788+kunzms@users.noreply.github.com> Date: Sat, 8 Feb 2020 11:31:34 -0800 Subject: [PATCH] fix: align tag dropdown menu with tag name (#13) --- .../components/common/tagInput/tagInput.tsx | 21 ++++++++++++------- .../common/tagInput/tagInputItem.tsx | 12 ++++++++++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/react/components/common/tagInput/tagInput.tsx b/src/react/components/common/tagInput/tagInput.tsx index d9c1d532..b06a112b 100644 --- a/src/react/components/common/tagInput/tagInput.tsx +++ b/src/react/components/common/tagInput/tagInput.tsx @@ -160,6 +160,7 @@ export class TagInput extends React.Component { ); } + public componentDidMount() { document.body.appendChild(this.portalDiv); this.setState({ @@ -324,7 +325,7 @@ export class TagInput extends React.Component {
{ ReactDOM.createPortal( - +
{ this.state.showColorPicker && @@ -348,7 +349,7 @@ export class TagInput extends React.Component {
{ ReactDOM.createPortal( - +
{ this.state.showDropDown && @@ -373,7 +374,7 @@ export class TagInput extends React.Component { return { // Align top right of source node (color picker) with top left of target node (tag row) points: [`${alignCorner}r`, `${alignCorner}l`], - // Offset source node by 10px in x and 20px in y + // Offset source node by 0px in x and 6px in y offset: [0, verticalOffset], // Offset targetNode by 30% of target node width in x and 40% of target node height // targetOffset: ["30%", "40%"], @@ -384,10 +385,10 @@ export class TagInput extends React.Component { private getFieldAlignConfig = () => { return { - // Align top right of source node (color picker) with top left of target node (tag row) - points: ["tr", "cr"], - // Offset source node by 10px in x and 20px in y - offset: [0, 3], + // Align top right of source node (dropdown) with top left of target node (tag name row) + points: ["tr", "br"], + // Offset source node by 6px in x and 3px in y + offset: [6, 3], // Offset targetNode by 30% of target node width in x and 40% of target node height // targetOffset: ["30%", "40%"], // Auto adjust position when source node is overflowed @@ -400,10 +401,14 @@ export class TagInput extends React.Component { return (node) ? node.getBoundingClientRect() : null; } - private getTarget = () => { + private getEditingTagNode = () => { return this.state.editingTagNode || document; } + private getEditingTagNameNode = () => { + return TagInputItem.getNameNode(this.state.editingTagNode) || document; + } + private renderTagItems = () => { let props = this.createTagItemProps(); const query = this.state.searchQuery; diff --git a/src/react/components/common/tagInput/tagInputItem.tsx b/src/react/components/common/tagInput/tagInputItem.tsx index 2cf9b30e..ec6c7041 100644 --- a/src/react/components/common/tagInput/tagInputItem.tsx +++ b/src/react/components/common/tagInput/tagInputItem.tsx @@ -59,6 +59,16 @@ export interface ITagInputItemState { } export default class TagInputItem extends React.Component { + + public static getNameNode(tagNode: Element): Element | undefined { + if (tagNode) { + return tagNode.getElementsByClassName(TagInputItem.TAG_NAME_CLASS_NAME)[0]; + } + return undefined; + } + + private static TAG_NAME_CLASS_NAME = "tag-item"; + public state: ITagInputItemState = { isBeingEdited: false, isLocked: false, @@ -148,7 +158,7 @@ export default class TagInputItem extends React.Component { - const classNames = ["tag-item"]; + const classNames = [TagInputItem.TAG_NAME_CLASS_NAME]; if (this.props.isSelected) { classNames.push("tag-item-selected"); }