Skip to content

Commit

Permalink
Merge branch 'main' of github.com:carbon-design-system/carbon
Browse files Browse the repository at this point in the history
  • Loading branch information
guidari committed Sep 19, 2024
2 parents e0280c3 + 72c80b3 commit d3bebda
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
43 changes: 43 additions & 0 deletions packages/react/docs/UsingFragmentsWithSwitcher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
The `Switcher` component is designed to have `SwitcherItem` components as its
direct children. However, there may be cases where you want to use React
Fragments or other nested structures within the `Switcher`. To accommodate we
recommend using the [`react-keyed-flatten-children`]
(https://www.npmjs.com/package/react-keyed-flatten-children#react-keyed-flatten-children)
package.

### Using react-keyed-flatten-children

The `react-keyed-flatten-children` package allows you to flatten arrays and
React Fragments into a regular, one-dimensional array while preserving element
and fragment keys.

1. Install the package:

```
npm install react-keyed-flatten-children
```

2. Import and use in your component:

```jsx
import flattenChildren from 'react-keyed-flatten-children';

const YourComponent = () => (
<Switcher>
{flattenChildren(
<>
<SwitcherItem>Item 1</SwitcherItem>
<SwitcherItem>Item 2</SwitcherItem>
<>
<SwitcherItem>Item 3</SwitcherItem>
<SwitcherItem>Item 4</SwitcherItem>
</>
</>
)}
</Switcher>
);
```

This approach allows you to use Fragments and nested structures with components
like `<Switcher>` without modifying their source code. It preserves keys and
props, ensuring stable rendering across updates.
4 changes: 2 additions & 2 deletions packages/react/src/components/DataTable/TableExpandHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type TableExpandHeaderPropsBase = {
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
['aria-label']: string;
['aria-label']?: string;

/**
* @deprecated The enableExpando prop is being replaced by `enableToggle`
Expand Down Expand Up @@ -150,7 +150,7 @@ TableExpandHeader.propTypes = {
className: PropTypes.string,

/**
* The enableExpando prop is being replaced by enableToggle
* The enableExpando prop is being replaced by TableExpandHeader
*/
enableExpando: deprecate(
PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('TableExpandHeader', () => {
<TableHead>
<TableRow>
<TableExpandHeader
ariaLabel="test-label"
aria-label="test-label"
isExpanded={false}
onExpand={jest.fn()}
className="custom-class"
Expand All @@ -43,12 +43,12 @@ describe('TableExpandHeader', () => {
expect(container).toMatchSnapshot();
});

it('should respect ariaLabel prop', () => {
it('should respect aria-label prop', () => {
render(
<Table>
<TableHead>
<TableRow>
<TableExpandHeader isExpanded enableToggle ariaLabel="Expand" />
<TableExpandHeader isExpanded aria-label="Expand" enableToggle />
</TableRow>
</TableHead>
</Table>
Expand Down
22 changes: 21 additions & 1 deletion packages/react/src/components/Tag/Tag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import { Add } from '@carbon/icons-react';
import { render, screen } from '@testing-library/react';
import React from 'react';
import Tag from './';
import Tag, { TagSkeleton } from './';
import DismissibleTag from './DismissibleTag';
import { AILabel } from '../AILabel';

const prefix = 'cds';

describe('Tag', () => {
describe('automated accessibility testing', () => {
it('should have no Axe violations', async () => {
Expand Down Expand Up @@ -63,4 +65,22 @@ describe('Tag', () => {
screen.getByRole('button', { name: 'AI - Show information' })
).toBeInTheDocument();
});

describe('Skeleton Tag', () => {
it('should render a skeleton state', () => {
const { container } = render(<TagSkeleton />);

const skeletonTag = container.querySelector(`.${prefix}--tag`);

expect(skeletonTag).toHaveClass(`${prefix}--skeleton`);
});

it('should render a skeleton state with a small size', () => {
const { container } = render(<TagSkeleton size="sm" />);

const skeletonTag = container.querySelector(`.${prefix}--tag`);

expect(skeletonTag).toHaveClass(`${prefix}--layout--size-sm`);
});
});
});

0 comments on commit d3bebda

Please sign in to comment.