Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EllipsisText): add title attribute #7681

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
max-inline-size: 100%;
}

/* Хак для того, чтобы убрать системный тултип в Safari */
inomdzhon marked this conversation as resolved.
Show resolved Hide resolved
.host.disableNativeTitle::after,
.host.disableNativeTitle .content::after {
content: '';
display: block;
}

.content {
min-inline-size: 1em;
overflow: hidden;
Expand Down
inomdzhon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRef } from 'react';
import { classNames } from '@vkontakte/vkjs';
import { getTextFromChildren } from '../../../lib/children';
import { useIsomorphicLayoutEffect } from '../../../lib/useIsomorphicLayoutEffect';
import type { HasRootRef } from '../../../types';
import type { RootComponentProps } from '../../RootComponent/RootComponent';
Expand All @@ -22,6 +23,10 @@ export interface EllipsisTextProps
* > @see [line-clamp](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-line-clamp)
*/
maxLines?: number;
/**
* Отключает отображение нативного тултипа с полным текстом
*/
disableNativeTitle?: boolean;
}

/** Компонент ограничивает текстовый контент убирая его в многоточие.
Expand All @@ -35,6 +40,7 @@ const EllipsisText = ({
children,
maxWidth,
maxLines = 1,
disableNativeTitle = false,
...restProps
}: EllipsisTextProps): React.ReactNode => {
const contentRef = useRef<HTMLSpanElement | null>(null);
Expand All @@ -46,7 +52,16 @@ const EllipsisText = ({
}, [contentRef, maxLines]);

return (
<span ref={getRootRef} className={classNames(styles.host, className)} {...restProps}>
<span
ref={getRootRef}
className={classNames(
styles.host,
disableNativeTitle && styles.disableNativeTitle,
className,
)}
title={disableNativeTitle ? undefined : getTextFromChildren(children)}
{...restProps}
>
<span
style={{ maxWidth }}
ref={contentRef}
Expand Down