Skip to content

Commit

Permalink
feat(react): add display names to forward ref components (#9591)
Browse files Browse the repository at this point in the history
* feat(react): add display names to forward ref components

* chore(snapshot): updated snapshot tests

* test(combo-box): update combobox test

* test(combo-box): update ListBoxMenuItem forward ref

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Alessandra Davila and kodiakhq[bot] authored Sep 22, 2021
1 parent 1d7d399 commit a1e11df
Show file tree
Hide file tree
Showing 28 changed files with 88 additions and 52 deletions.
3 changes: 3 additions & 0 deletions packages/carbon-react/src/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function Popover({
);
}

Popover.displayName = 'Popover';
Popover.propTypes = {
/**
* Specify how the popover should align with the trigger element
Expand Down Expand Up @@ -122,6 +123,8 @@ const PopoverContent = React.forwardRef(function PopoverContent(
);
});

PopoverContent.displayName = 'PopoverContent';

PopoverContent.propTypes = {
/**
* Provide a custom element or component to render the top-level node for the
Expand Down
16 changes: 16 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ Map {
"shouldFilterItem": [Function],
"type": "default",
},
"displayName": "ComboBox",
"propTypes": Object {
"ariaLabel": Object {
"type": "string",
Expand Down Expand Up @@ -4692,6 +4693,7 @@ Map {
},
"PaginationNav" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "PaginationNav",
"propTypes": Object {
"className": Object {
"type": "string",
Expand Down Expand Up @@ -4730,6 +4732,7 @@ Map {
"onClick": [Function],
"size": "",
},
"displayName": "ControlledPasswordInput",
"propTypes": Object {
"className": Object {
"type": "string",
Expand Down Expand Up @@ -4841,6 +4844,7 @@ Map {
"onClick": [Function],
"size": "",
},
"displayName": "PasswordInput",
"propTypes": Object {
"className": Object {
"type": "string",
Expand Down Expand Up @@ -6046,6 +6050,7 @@ Map {
"onClick": [Function],
"size": "",
},
"displayName": "ControlledPasswordInput",
"propTypes": Object {
"className": Object {
"type": "string",
Expand Down Expand Up @@ -6157,6 +6162,7 @@ Map {
"onClick": [Function],
"size": "",
},
"displayName": "PasswordInput",
"propTypes": Object {
"className": Object {
"type": "string",
Expand Down Expand Up @@ -6901,6 +6907,7 @@ Map {
},
"ToolbarTitle" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "ToolbarTitle",
"propTypes": Object {
"title": Object {
"type": "string",
Expand All @@ -6910,6 +6917,7 @@ Map {
},
"ToolbarOption" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "ToolbarOption",
"propTypes": Object {
"children": Object {
"type": "node",
Expand All @@ -6919,6 +6927,7 @@ Map {
},
"ToolbarDivider" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "ToolbarDivider",
"render": [Function],
},
"ToolbarSearch" => Object {
Expand Down Expand Up @@ -7589,6 +7598,7 @@ Map {
},
"HeaderMenuItem" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "HeaderMenuItem",
"propTypes": Object {
"children": Object {
"isRequired": true,
Expand Down Expand Up @@ -7701,6 +7711,7 @@ Map {
},
"Switcher" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "Switcher",
"propTypes": Object {
"aria-label": [Function],
"aria-labelledby": [Function],
Expand All @@ -7716,6 +7727,7 @@ Map {
},
"SwitcherItem" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "SwitcherItem",
"propTypes": Object {
"aria-label": [Function],
"aria-labelledby": [Function],
Expand Down Expand Up @@ -7769,6 +7781,7 @@ Map {
"isFixedNav": false,
"isPersistent": true,
},
"displayName": "SideNav",
"propTypes": Object {
"addFocusListeners": Object {
"type": "bool",
Expand Down Expand Up @@ -7936,6 +7949,7 @@ Map {
"element": "a",
"large": false,
},
"displayName": "SideNavLink",
"propTypes": Object {
"children": Object {
"isRequired": true,
Expand Down Expand Up @@ -7987,6 +8001,7 @@ Map {
},
"SideNavMenuItem" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "SideNavMenuItem",
"propTypes": Object {
"children": Object {
"type": "node",
Expand All @@ -8002,6 +8017,7 @@ Map {
},
"SideNavSwitcher" => Object {
"$$typeof": Symbol(react.forward_ref),
"displayName": "SideNavSwitcher",
"propTypes": Object {
"className": Object {
"type": "string",
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/ComboBox/ComboBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('ComboBox', () => {

for (let i = 0; i < mockProps.items.length; i++) {
openMenu(wrapper);
wrapper.find('ForwardRef(ListBoxMenuItem)').at(i).simulate('click');
wrapper.find('ListBoxMenuItem').at(i).simulate('click');
expect(mockProps.onChange).toHaveBeenCalledTimes(i + 1);
expect(mockProps.onChange).toHaveBeenCalledWith({
selectedItem: mockProps.items[i],
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('ComboBox', () => {
it('should let the user select an option by clicking on the option node', () => {
const wrapper = mount(<ComboBox {...mockProps} />);
openMenu(wrapper);
wrapper.find('ForwardRef(ListBoxMenuItem)').at(0).simulate('click');
wrapper.find('ListBoxMenuItem').at(0).simulate('click');
expect(mockProps.onChange).toHaveBeenCalledTimes(1);
expect(mockProps.onChange).toHaveBeenCalledWith({
selectedItem: mockProps.items[0],
Expand All @@ -104,7 +104,7 @@ describe('ComboBox', () => {
mockProps.onChange.mockClear();

openMenu(wrapper);
wrapper.find('ForwardRef(ListBoxMenuItem)').at(1).simulate('click');
wrapper.find('ListBoxMenuItem').at(1).simulate('click');
expect(mockProps.onChange).toHaveBeenCalledTimes(1);
expect(mockProps.onChange).toHaveBeenCalledWith({
selectedItem: mockProps.items[1],
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ const ComboBox = React.forwardRef((props, ref) => {
);
});

ComboBox.displayName = 'ComboBox';
ComboBox.propTypes = {
/**
* 'aria-label' of the ListBox component.
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('Dropdown', () => {
it('should let the user select an option by clicking on the option node', () => {
const wrapper = mount(<Dropdown {...mockProps} />);
openMenu(wrapper);
wrapper.find('ForwardRef(ListBoxMenuItem)').at(0).simulate('click');
wrapper.find('ListBoxMenuItem').at(0).simulate('click');
expect(mockProps.onChange).toHaveBeenCalledTimes(1);
expect(mockProps.onChange).toHaveBeenCalledWith({
selectedItem: mockProps.items[0],
Expand All @@ -143,7 +143,7 @@ describe('Dropdown', () => {
mockProps.onChange.mockClear();

openMenu(wrapper);
wrapper.find('ForwardRef(ListBoxMenuItem)').at(1).simulate('click');
wrapper.find('ListBoxMenuItem').at(1).simulate('click');
expect(mockProps.onChange).toHaveBeenCalledTimes(1);
expect(mockProps.onChange).toHaveBeenCalledWith({
selectedItem: mockProps.items[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ exports[`Dropdown should render custom item components 1`] = `
role="listbox"
tabIndex={-1}
>
<ForwardRef(ListBoxMenuItem)
<ListBoxMenuItem
aria-selected="false"
id="downshift-6-item-0"
isActive={false}
Expand Down Expand Up @@ -330,8 +330,8 @@ exports[`Dropdown should render custom item components 1`] = `
</itemToElement>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
<ForwardRef(ListBoxMenuItem)
</ListBoxMenuItem>
<ListBoxMenuItem
aria-selected="false"
id="downshift-6-item-1"
isActive={false}
Expand Down Expand Up @@ -366,8 +366,8 @@ exports[`Dropdown should render custom item components 1`] = `
</itemToElement>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
<ForwardRef(ListBoxMenuItem)
</ListBoxMenuItem>
<ListBoxMenuItem
aria-selected="false"
id="downshift-6-item-2"
isActive={false}
Expand Down Expand Up @@ -402,8 +402,8 @@ exports[`Dropdown should render custom item components 1`] = `
</itemToElement>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
<ForwardRef(ListBoxMenuItem)
</ListBoxMenuItem>
<ListBoxMenuItem
aria-selected="false"
id="downshift-6-item-3"
isActive={false}
Expand Down Expand Up @@ -438,8 +438,8 @@ exports[`Dropdown should render custom item components 1`] = `
</itemToElement>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
<ForwardRef(ListBoxMenuItem)
</ListBoxMenuItem>
<ListBoxMenuItem
aria-selected="false"
id="downshift-6-item-4"
isActive={false}
Expand Down Expand Up @@ -474,7 +474,7 @@ exports[`Dropdown should render custom item components 1`] = `
</itemToElement>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
</ListBoxMenuItem>
</div>
</ListBoxMenu>
</div>
Expand Down Expand Up @@ -604,7 +604,7 @@ exports[`Dropdown should render with strings as items 1`] = `
role="listbox"
tabIndex={-1}
>
<ForwardRef(ListBoxMenuItem)
<ListBoxMenuItem
aria-selected="false"
id="downshift-4-item-0"
isActive={false}
Expand All @@ -628,8 +628,8 @@ exports[`Dropdown should render with strings as items 1`] = `
zar
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
<ForwardRef(ListBoxMenuItem)
</ListBoxMenuItem>
<ListBoxMenuItem
aria-selected="false"
id="downshift-4-item-1"
isActive={false}
Expand All @@ -653,7 +653,7 @@ exports[`Dropdown should render with strings as items 1`] = `
doz
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
</ListBoxMenuItem>
</div>
</ListBoxMenu>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/ListBox/ListBoxMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ListBoxMenuItem = React.forwardRef(function ListBoxMenuItem(
);
});

ListBoxMenuItem.displayName = 'ListBoxMenuItem';
ListBoxMenuItem.propTypes = {
/**
* Specify any children nodes that should be rendered inside of the ListBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`ListBoxMenu should render 1`] = `
id="test-listbox"
role="listbox"
>
<ForwardRef(ListBoxMenuItem)
<ListBoxMenuItem
isActive={false}
isHighlighted={false}
>
Expand All @@ -22,7 +22,7 @@ exports[`ListBoxMenu should render 1`] = `
Hello
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
</ListBoxMenuItem>
</div>
</ListBoxMenu>
`;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ListBoxMenuItem should render 1`] = `
<ForwardRef(ListBoxMenuItem)
<ListBoxMenuItem
isActive={false}
isHighlighted={false}
>
Expand All @@ -16,11 +16,11 @@ exports[`ListBoxMenuItem should render 1`] = `
</span>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
</ListBoxMenuItem>
`;

exports[`ListBoxMenuItem should render 2`] = `
<ForwardRef(ListBoxMenuItem)
<ListBoxMenuItem
isActive={true}
isHighlighted={false}
>
Expand All @@ -35,11 +35,11 @@ exports[`ListBoxMenuItem should render 2`] = `
</span>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
</ListBoxMenuItem>
`;

exports[`ListBoxMenuItem should render 3`] = `
<ForwardRef(ListBoxMenuItem)
<ListBoxMenuItem
isActive={false}
isHighlighted={true}
>
Expand All @@ -54,5 +54,5 @@ exports[`ListBoxMenuItem should render 3`] = `
</span>
</div>
</div>
</ForwardRef(ListBoxMenuItem)>
</ListBoxMenuItem>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
generateGenericItem,
} from '../../ListBox/test-helpers';

const listItemName = 'ForwardRef(ListBoxMenuItem)';
const listItemName = 'ListBoxMenuItem';
const openMenu = (wrapper) => {
wrapper.find(`[role="combobox"]`).simulate('click');
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ PaginationOverflow.propTypes = {
translateWithId: PropTypes.func,
};

PaginationNav.displayName = 'PaginationNav';
PaginationNav.propTypes = {
/**
* Additional CSS class names.
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const PopoverContent = React.forwardRef(function PopoverContent(
);
});

PopoverContent.displayName = 'PopoverContent';
PopoverContent.propTypes = {
/**
* Provide a custom element or component to render the top-level node for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const ControlledPasswordInput = React.forwardRef(
}
);

ControlledPasswordInput.displayName = 'ControlledPasswordInput';
ControlledPasswordInput.propTypes = {
/**
* Provide a custom className that is applied directly to the underlying
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/TextInput/PasswordInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const PasswordInput = React.forwardRef(function PasswordInput(
);
});

PasswordInput.displayName = 'PasswordInput';
PasswordInput.propTypes = {
/**
* Provide a custom className that is applied directly to the underlying
Expand Down
Loading

0 comments on commit a1e11df

Please sign in to comment.