mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix badge not expanding on click when appropriate
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
6d37019089
commit
dd7ac03cce
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import styles from "./badge.module.scss";
|
import styles from "./badge.module.scss";
|
||||||
|
|
||||||
import React, { createRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { action, observable } from "mobx";
|
import { action, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { cssNames } from "../../utils/cssNames";
|
import { cssNames } from "../../utils/cssNames";
|
||||||
@ -40,12 +40,26 @@ export const Badge = withTooltip(observer(({
|
|||||||
children,
|
children,
|
||||||
...elemProps
|
...elemProps
|
||||||
}: BadgeProps) => {
|
}: BadgeProps) => {
|
||||||
const elem = createRef<HTMLDivElement>();
|
const elem = useRef<HTMLDivElement>(null);
|
||||||
|
const elemHasBeenSet = useRef(false);
|
||||||
const [isExpanded, setIsExpanded] = useState(false);
|
const [isExpanded, setIsExpanded] = useState(false);
|
||||||
|
const [isExpandable, setIsExpandable] = useState(expandable);
|
||||||
|
|
||||||
const isExpandable = expandable && elem.current
|
useEffect(() => {
|
||||||
? elem.current.clientWidth < elem.current.scrollWidth
|
if (elemHasBeenSet.current) {
|
||||||
: false;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elem.current) {
|
||||||
|
elemHasBeenSet.current = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsExpandable((
|
||||||
|
expandable && elem.current
|
||||||
|
? elem.current.clientWidth < elem.current.scrollWidth
|
||||||
|
: false
|
||||||
|
));
|
||||||
|
}, [expandable, elem.current]);
|
||||||
|
|
||||||
const onMouseUp = action(() => {
|
const onMouseUp = action(() => {
|
||||||
if (!isExpandable || badgeMeta.hasTextSelected) {
|
if (!isExpandable || badgeMeta.hasTextSelected) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user