Not closing badge if user started to select text

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev committed 2021-07-13 16:16:52 +03:00
1 parent 4130c3ce91
commit 5ba5ed488f
1 file changed
+10 -7
+10 -7
View File
@@ -36,13 +36,9 @@ export interface BadgeProps extends React.HTMLAttributes<any>, TooltipDecoratorP
disabled?: boolean;
}
const badgeMeta = observable({
hasTextSelected: false,
});
// Common handler for all Badge instances
document.addEventListener("selectionchange", () => {
badgeMeta.hasTextSelected = window.getSelection().toString().trim().length > 0;
Badge.badgeMeta.hasTextSelected ||= window.getSelection().toString().trim().length > 0;
});
@withTooltip
@@ -52,6 +48,10 @@ export class Badge extends React.Component<BadgeProps> {
expandable: true
};
static badgeMeta = observable({
hasTextSelected: false
});
@observable.ref elem: HTMLElement;
@observable isExpanded = false;
@@ -68,8 +68,11 @@ export class Badge extends React.Component<BadgeProps> {
@boundMethod
onMouseUp() {
if (!this.isExpandable || badgeMeta.hasTextSelected) return; // no action required
this.isExpanded = !this.isExpanded;
if (!this.isExpandable || Badge.badgeMeta.hasTextSelected) {
Badge.badgeMeta.hasTextSelected = false;
} else {
this.isExpanded = !this.isExpanded;
}
}
@boundMethod