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

Tag ellipses with Tooltip #15959

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion e2e/components/InteractiveTag/InteractiveTag-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ test.describe('@avt InteractiveTag', () => {
theme: 'white',
},
});
const tooltip = page.getByRole('tooltip');
const button = page.getByRole('button').first();
await expect(button).toBeVisible();
await page.keyboard.press('Tab');
await expect(button).toBeFocused();
await expect(tooltip).toHaveAttribute('aria-hidden', 'false');
});

test('@avt-keyboard-nav OperationalTag', async ({ page }) => {
Expand All @@ -71,6 +73,10 @@ test.describe('@avt InteractiveTag', () => {
await expect(button).toBeVisible();
await page.keyboard.press('Tab');
await expect(button).toBeFocused();
await expect(page.getByRole('tooltip')).toHaveAttribute(
'aria-hidden',
'false'
);
await expect(button).toHaveClass(/cds--tag--red/);

await page.keyboard.press('Tab');
Expand All @@ -87,7 +93,7 @@ test.describe('@avt InteractiveTag', () => {
// Expecte the OperationalTag with tooltip be focusable and visible
await expect(page.getByRole('button').nth(10)).toBeFocused();
await page.keyboard.press('Enter');
await expect(page.getByText('View More')).toBeVisible();
await expect(page.getByText('Tag 1 name').first()).toBeVisible();
});

test('@avt-keyboard-nav SelectableTag', async ({ page }) => {
Expand All @@ -104,5 +110,10 @@ test.describe('@avt InteractiveTag', () => {
await expect(tag).toBeFocused();
await page.keyboard.press('Enter');
await expect(tag).toHaveClass(/cds--tag--selectable-selected/);
await page.keyboard.press('Tab');
await expect(page.getByRole('tooltip')).toHaveAttribute(
'aria-hidden',
'false'
);
});
});
19 changes: 19 additions & 0 deletions e2e/components/Tag/Tag-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ test.describe('@avt Tag', () => {
});
await expect(page).toHaveNoACViolations('Tag-skeleton');
});

test('@avt-keyboard-nav Tag', async ({ page }) => {
await visitStory(page, {
component: 'Tag',
id: 'components-tag--read-only',
globals: {
theme: 'white',
},
});
const button = page.getByRole('button').first();
await expect(button).toBeVisible();
await page.keyboard.press('Tab');
await expect(button).toBeFocused();
// Expect Tooltip to be visible
await expect(page.getByRole('tooltip')).toHaveAttribute(
'aria-hidden',
'false'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8438,6 +8438,9 @@ Map {
"slug": Object {
"type": "node",
},
"text": Object {
"type": "string",
},
"title": [Function],
"type": Object {
"args": Array [
Expand Down
49 changes: 25 additions & 24 deletions packages/react/src/components/Tag/DismissibleTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import { Close } from '@carbon/icons-react';
const getInstanceId = setupGetInstanceId();

export interface DismissibleTagBaseProps {
/**
* Provide content to be rendered inside of a `DismissibleTag`
*/
children?: React.ReactNode;

/**
* Provide a custom className that is applied to the containing <span>
*/
Expand Down Expand Up @@ -59,6 +54,11 @@ export interface DismissibleTagBaseProps {
*/
slug?: ReactNodeLike;

/**
* Provide text to be rendered inside of a the tag.
*/
text?: string;

/**
* Text to show on clear filters
*/
Expand All @@ -76,7 +76,6 @@ export type DismissibleTagProps<T extends React.ElementType> = PolymorphicProps<
>;

const DismissibleTag = <T extends React.ElementType>({
children,
className,
disabled,
id,
Expand All @@ -85,6 +84,7 @@ const DismissibleTag = <T extends React.ElementType>({
onClose,
slug,
size,
text,
type,
...other
}: DismissibleTagProps<T>) => {
Expand Down Expand Up @@ -118,30 +118,26 @@ const DismissibleTag = <T extends React.ElementType>({
renderIcon={renderIcon}
disabled={disabled}
className={tagClasses}
text={text}
id={tagId}
{...otherProps}>
<div className={`${prefix}--interactive--tag-children`}>
{children}
{normalizedSlug}
<button
type="button"
className={`${prefix}--tag__close-icon`}
onClick={handleClose}
disabled={disabled}
aria-label={title}
title={title}>
<Close />
</button>
</div>
{normalizedSlug}
<button
onFocus={(event) => {
event.stopPropagation();
}}
type="button"
className={`${prefix}--tag__close-icon`}
onClick={handleClose}
disabled={disabled}
aria-label={title}
title={title}>
<Close />
</button>
</Tag>
);
};
DismissibleTag.propTypes = {
/**
* Provide content to be rendered inside of a `DismissibleTag`
*/
children: PropTypes.node,

/**
* Provide a custom className that is applied to the containing <span>
*/
Expand Down Expand Up @@ -179,6 +175,11 @@ DismissibleTag.propTypes = {
*/
slug: PropTypes.node,

/**
* Provide text to be rendered inside of a the tag.
*/
text: PropTypes.string,

/**
* Text to show on clear filters
*/
Expand Down
Loading
Loading