Skip to content

Commit

Permalink
fix: disable move tag and support renaming when searching (microsoft#618
Browse files Browse the repository at this point in the history
)

* fix: disable move tag and support renaming when searching

* fix: remove console log
  • Loading branch information
stew-ro authored Sep 25, 2020
1 parent 4163edc commit cac1e8e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/react/components/common/tagInput/tagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class TagInput extends React.Component<ITagInputProps, ITagInputState> {
};

const { selectedTag, tagOperation } = this.state;
const selectedTagRef = selectedTag ? this.tagItemRefs.get(selectedTag.name).getTagNameRef() : null;
const selectedTagRef = selectedTag ? this.tagItemRefs.get(selectedTag.name)?.getTagNameRef() : null;

return (
<div className="tag-input">
Expand All @@ -178,6 +178,7 @@ export class TagInput extends React.Component<ITagInputProps, ITagInputState> {
searchTags: !this.state.searchTags,
searchQuery: "",
})}
searchingTags={this.state.searchQuery.length > 0}
onRenameTag={this.onRenameTag}
onLockTag={this.onLockTag}
onDelete={this.onDeleteTag}
Expand All @@ -198,6 +199,7 @@ export class TagInput extends React.Component<ITagInputProps, ITagInputState> {
onChange={(e) => this.setState({ searchQuery: e.target.value })}
placeholder="Search tags"
autoFocus={true}
onFocus={() => this.setState({selectedTag: null, tagOperation: TagOperationMode.Rename})}
/>
<FontIcon iconName="Search" />
</div>
Expand Down Expand Up @@ -648,6 +650,7 @@ export class TagInput extends React.Component<ITagInputProps, ITagInputState> {
},
text: strings.tags.toolbar.moveUp,
onClick: this.onMenuItemClick,
disabled: this.state.searchQuery.length > 0,
},
{
key: TagMenuItem.MoveDown,
Expand All @@ -656,6 +659,7 @@ export class TagInput extends React.Component<ITagInputProps, ITagInputState> {
},
text: strings.tags.toolbar.moveDown,
onClick: this.onMenuItemClick,
disabled: this.state.searchQuery.length > 0,
},
{
key: TagMenuItem.Delete,
Expand Down
45 changes: 32 additions & 13 deletions src/react/components/common/tagInput/tagInputToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { ITag } from "../../../../models/applicationState";
enum Categories {
General,
Separator,
Modifier,
RenameModifier,
MoveModifier,
}

/** Properties for tag input toolbar */
Expand All @@ -28,6 +29,7 @@ export interface ITagInputToolbarProps {
onDelete: (tag: ITag) => void;
/** Function to call when one of the re-order buttons is clicked */
onReorder: (tag: ITag, displacement: number) => void;
searchingTags: boolean;
}

interface ITagInputToolbarItemProps {
Expand Down Expand Up @@ -68,38 +70,44 @@ export default class TagInputToolbar extends React.Component<ITagInputToolbarPro
{
displayName: strings.tags.toolbar.rename,
icon: "Rename",
category: Categories.Modifier,
category: Categories.RenameModifier,
handler: this.handleRename,
},
{
displayName: strings.tags.toolbar.moveUp,
icon: "Up",
category: Categories.Modifier,
category: Categories.MoveModifier,
handler: this.handleMoveUp,
},
{
displayName: strings.tags.toolbar.moveDown,
icon: "Down",
category: Categories.Modifier,
category: Categories.MoveModifier,
handler: this.handleMoveDown,
},
{
displayName: strings.tags.toolbar.delete,
icon: "Delete",
category: Categories.Modifier,
category: Categories.MoveModifier,
handler: this.handleDelete,
},
];
}

private renderItems = () => {
const modifierDisabled = !this.props.selectedTag;
const modifierClassNames = ["tag-input-toolbar-iconbutton"];
if (modifierDisabled) {
modifierClassNames.push("tag-input-toolbar-iconbutton-disabled");
const moveModifierDisabled = !this.props.selectedTag || this.props.searchingTags;
const renameModifierDisabled = !this.props.selectedTag;
const moveModifierClassNames = ["tag-input-toolbar-iconbutton"];
const renameModifierClassNames = ["tag-input-toolbar-iconbutton"];
if (moveModifierDisabled) {
moveModifierClassNames.push("tag-input-toolbar-iconbutton-disabled");
}
if (renameModifierDisabled) {
renameModifierClassNames.push("tag-input-toolbar-iconbutton-disabled");
}

const modifierClassName = modifierClassNames.join(" ");
const moveModifierClassName = moveModifierClassNames.join(" ");
const renameModifierClassName = renameModifierClassNames.join(" ");

return(
this.getToolbarItems().map((itemConfig, index) => {
Expand All @@ -116,14 +124,25 @@ export default class TagInputToolbar extends React.Component<ITagInputToolbarPro
);
} else if (itemConfig.category === Categories.Separator) {
return (<div className="tag-input-toolbar-separator" key={itemConfig.displayName}></div>);
} else if (itemConfig.category === Categories.Modifier) {
} else if (itemConfig.category === Categories.RenameModifier) {
return (
<IconButton
key={itemConfig.displayName}
disabled={renameModifierDisabled}
title={itemConfig.displayName}
ariaLabel={itemConfig.displayName}
className={renameModifierClassName}
iconProps={{iconName: itemConfig.icon}}
onClick={(e) => this.onToolbarItemClick(e, itemConfig)} />
);
} else if (itemConfig.category === Categories.MoveModifier) {
return (
<IconButton
key={itemConfig.displayName}
disabled={modifierDisabled}
disabled={moveModifierDisabled}
title={itemConfig.displayName}
ariaLabel={itemConfig.displayName}
className={modifierClassName}
className={moveModifierClassName}
iconProps={{iconName: itemConfig.icon}}
onClick={(e) => this.onToolbarItemClick(e, itemConfig)} />
);
Expand Down

0 comments on commit cac1e8e

Please sign in to comment.