Skip to content

Commit

Permalink
[setup] Add missing EuiTextTruncate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Sep 21, 2023
1 parent cafa0ba commit 82f0792
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
exports[`EuiTextTruncate renders 1`] = `
<div
aria-label="aria-label"
class="testClass1 testClass2 emotion-euiTextTruncate-euiTestCss"
class="euiTextTruncate testClass1 testClass2 emotion-euiTextTruncate-euiTestCss"
data-test-subj="test subject string"
>
<span
class="euiTextTruncate__fullText"
data-test-subj="fullText"
>
Hello world
Expand Down
4 changes: 2 additions & 2 deletions src/components/text_truncate/text_truncate.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export const euiTextTruncateStyles = {
* and there'll be no need for the entire component at that point 🙏
*/
// Makes the truncated text unselectable/un-clickable
truncatedText: css`
euiTextTruncate__truncatedText: css`
user-select: none;
pointer-events: none;
`,
// Positions the full text on top of the truncated text (so that clicking targets it)
// and gives it a color opacity of 0 so that it's not actually visible
fullText: css`
euiTextTruncate__fullText: css`
position: absolute;
inset: 0;
overflow: hidden;
Expand Down
20 changes: 15 additions & 5 deletions src/components/text_truncate/text_truncate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import React, {
useMemo,
useCallback,
} from 'react';
import classNames from 'classnames';

import { useCombinedRefs } from '../../services';
import {
Expand All @@ -24,7 +25,7 @@ import {
import type { CommonProps } from '../common';

import { TruncationUtilsWithDOM, TruncationUtilsWithCanvas } from './utils';
import { euiTextTruncateStyles } from './text_truncate.styles';
import { euiTextTruncateStyles as styles } from './text_truncate.styles';

const TRUNCATION_TYPES = ['end', 'start', 'startEnd', 'middle'] as const;
export type EuiTextTruncationTypes = (typeof TRUNCATION_TYPES)[number];
Expand Down Expand Up @@ -129,6 +130,7 @@ const EuiTextTruncateWithWidth: FunctionComponent<
ellipsis = '…',
containerRef,
measurementRenderAPI = 'dom',
className,
...rest
}) => {
// Note: This needs to be a state and not a ref to trigger a rerender on mount
Expand Down Expand Up @@ -214,26 +216,34 @@ const EuiTextTruncateWithWidth: FunctionComponent<

return (
<div
css={euiTextTruncateStyles.euiTextTruncate}
className={classNames('euiTextTruncate', className)}
css={styles.euiTextTruncate}
ref={refs}
title={isTruncating ? text : undefined}
{...rest}
>
{isTruncating ? (
<>
<span
css={euiTextTruncateStyles.truncatedText}
className="euiTextTruncate__truncatedText"
css={styles.euiTextTruncate__truncatedText}
aria-hidden
data-test-subj="truncatedText"
>
{children ? children(truncatedText) : truncatedText}
</span>
<span css={euiTextTruncateStyles.fullText} data-test-subj="fullText">
<span
className="euiTextTruncate__fullText"
css={styles.euiTextTruncate__fullText}
data-test-subj="fullText"
>
{text}
</span>
</>
) : (
<span data-test-subj="fullText">{text}</span>
<span className="euiTextTruncate__fullText" data-test-subj="fullText">
{children ? children(text) : text}
</span>
)}
</div>
);
Expand Down

0 comments on commit 82f0792

Please sign in to comment.