Fix wrong room topic tooltip position (#10667)

* Fix wrong room topic tooltip position

* Update snapshots

* Fix tests
This commit is contained in:
Michael Telatynski 2023-04-20 09:25:53 +01:00 committed by GitHub
parent 93b4ee654b
commit 1efa82917a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 97 deletions

View file

@ -103,10 +103,17 @@ export default function RoomTopic({ room, ...props }: IProps): JSX.Element {
const className = classNames(props.className, "mx_RoomTopic"); const className = classNames(props.className, "mx_RoomTopic");
return ( return (
<div {...props} ref={ref} onClick={onClick} dir="auto" className={className}> <TooltipTarget
<TooltipTarget label={_t("Click to read topic")} alignment={Alignment.Bottom} ignoreHover={ignoreHover}> {...props}
ref={ref}
onClick={onClick}
dir="auto"
tooltipTargetClassName={className}
label={_t("Click to read topic")}
alignment={Alignment.Bottom}
ignoreHover={ignoreHover}
>
<Linkify>{body}</Linkify> <Linkify>{body}</Linkify>
</TooltipTarget> </TooltipTarget>
</div>
); );
} }

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React, { HTMLAttributes } from "react"; import React, { forwardRef, HTMLAttributes } from "react";
import useFocus from "../../../hooks/useFocus"; import useFocus from "../../../hooks/useFocus";
import useHover from "../../../hooks/useHover"; import useHover from "../../../hooks/useHover";
@ -29,7 +29,9 @@ interface IProps extends HTMLAttributes<HTMLSpanElement>, Omit<ITooltipProps, "v
* Generic tooltip target element that handles tooltip visibility state * Generic tooltip target element that handles tooltip visibility state
* and displays children * and displays children
*/ */
const TooltipTarget: React.FC<IProps> = ({ const TooltipTarget = forwardRef<HTMLDivElement, IProps>(
(
{
children, children,
tooltipTargetClassName, tooltipTargetClassName,
// tooltip pass through props // tooltip pass through props
@ -41,7 +43,9 @@ const TooltipTarget: React.FC<IProps> = ({
maxParentWidth, maxParentWidth,
ignoreHover, ignoreHover,
...rest ...rest
}) => { },
ref,
) => {
const [isFocused, focusProps] = useFocus(); const [isFocused, focusProps] = useFocus();
const [isHovering, hoverProps] = useHover(ignoreHover || (() => false)); const [isHovering, hoverProps] = useHover(ignoreHover || (() => false));
@ -67,11 +71,13 @@ const TooltipTarget: React.FC<IProps> = ({
aria-describedby={id} aria-describedby={id}
className={tooltipTargetClassName} className={tooltipTargetClassName}
{...rest} {...rest}
ref={ref}
> >
{children} {children}
{tooltip} {tooltip}
</div> </div>
); );
}; },
);
export default TooltipTarget; export default TooltipTarget;

View file

@ -52,7 +52,8 @@ describe("PosthogAnalytics", () => {
beforeEach(() => { beforeEach(() => {
fakePosthog = getFakePosthog(); fakePosthog = getFakePosthog();
window.crypto = { Object.defineProperty(window, "crypto", {
value: {
subtle: { subtle: {
digest: async (_: AlgorithmIdentifier, encodedMessage: BufferSource) => { digest: async (_: AlgorithmIdentifier, encodedMessage: BufferSource) => {
const message = new TextDecoder().decode(encodedMessage); const message = new TextDecoder().decode(encodedMessage);
@ -61,15 +62,17 @@ describe("PosthogAnalytics", () => {
for (let c = 0; c < hexHash.length; c += 2) { for (let c = 0; c < hexHash.length; c += 2) {
bytes.push(parseInt(hexHash.slice(c, c + 2), 16)); bytes.push(parseInt(hexHash.slice(c, c + 2), 16));
} }
return bytes as unknown as ArrayBuffer; return bytes;
}, },
} as unknown as SubtleCrypto, },
} as unknown as Crypto; },
});
}); });
afterEach(() => { afterEach(() => {
// @ts-ignore Object.defineProperty(window, "crypto", {
window.crypto = null; value: null,
});
SdkConfig.unset(); // we touch the config, so clean up SdkConfig.unset(); // we touch the config, so clean up
}); });

View file

@ -55,8 +55,6 @@ exports[`RoomView for a local room in state CREATING should match the snapshot 1
<div <div
class="mx_RoomHeader_topic mx_RoomTopic" class="mx_RoomHeader_topic mx_RoomTopic"
dir="auto" dir="auto"
>
<div
tabindex="0" tabindex="0"
> >
<span <span
@ -64,7 +62,6 @@ exports[`RoomView for a local room in state CREATING should match the snapshot 1
/> />
</div> </div>
</div> </div>
</div>
</header> </header>
<div <div
class="mx_RoomView_body" class="mx_RoomView_body"
@ -149,8 +146,6 @@ exports[`RoomView for a local room in state ERROR should match the snapshot 1`]
<div <div
class="mx_RoomHeader_topic mx_RoomTopic" class="mx_RoomHeader_topic mx_RoomTopic"
dir="auto" dir="auto"
>
<div
tabindex="0" tabindex="0"
> >
<span <span
@ -158,7 +153,6 @@ exports[`RoomView for a local room in state ERROR should match the snapshot 1`]
/> />
</div> </div>
</div> </div>
</div>
</header> </header>
<main <main
class="mx_RoomView_body" class="mx_RoomView_body"
@ -339,8 +333,6 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] =
<div <div
class="mx_RoomHeader_topic mx_RoomTopic" class="mx_RoomHeader_topic mx_RoomTopic"
dir="auto" dir="auto"
>
<div
tabindex="0" tabindex="0"
> >
<span <span
@ -348,7 +340,6 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] =
/> />
</div> </div>
</div> </div>
</div>
</header> </header>
<main <main
class="mx_RoomView_body" class="mx_RoomView_body"
@ -606,8 +597,6 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
<div <div
class="mx_RoomHeader_topic mx_RoomTopic" class="mx_RoomHeader_topic mx_RoomTopic"
dir="auto" dir="auto"
>
<div
tabindex="0" tabindex="0"
> >
<span <span
@ -615,7 +604,6 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
/> />
</div> </div>
</div> </div>
</div>
</header> </header>
<main <main
class="mx_RoomView_body" class="mx_RoomView_body"

View file

@ -75,13 +75,13 @@ describe("MegolmExportEncryption", function () {
let MegolmExportEncryption: typeof MegolmExportEncryptionExport; let MegolmExportEncryption: typeof MegolmExportEncryptionExport;
beforeEach(() => { beforeEach(() => {
window.crypto = { Object.defineProperty(window, "crypto", {
value: {
getRandomValues, getRandomValues,
randomUUID: jest.fn().mockReturnValue("not-random-uuid"), randomUUID: jest.fn().mockReturnValue("not-random-uuid"),
subtle: webCrypto.subtle, subtle: webCrypto.subtle,
}; },
// @ts-ignore for some reason including it in the object above gets ignored });
window.crypto.subtle = webCrypto.subtle;
MegolmExportEncryption = require("../../src/utils/MegolmExportEncryption"); MegolmExportEncryption = require("../../src/utils/MegolmExportEncryption");
}); });