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

Some components do not have a 'displayName' set #9459

Closed
1 of 2 tasks
dcwarwick opened this issue Aug 11, 2021 · 1 comment · Fixed by #9591
Closed
1 of 2 tasks

Some components do not have a 'displayName' set #9459

dcwarwick opened this issue Aug 11, 2021 · 1 comment · Fixed by #9591
Assignees
Labels
package: react carbon-components-react type: bug 🐛

Comments

@dcwarwick
Copy link
Contributor

dcwarwick commented Aug 11, 2021

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you're having.

React generates an automatic 'name' for components based on the class name or function name of the render function for hook-based components. However, React.forwardRef prevents this being done successfully. When hook-based components use React.forwardRef it is helpful to set a displayName field on the result so that the component shows up recognisably in dev tools and debugging etc.

Some components do set displayName, e.g. Button, but others do not, e.g. TextInput.

The deprecateFieldOnObject function added in #9008 by @tay1orjones relies on displayName to be set in order to produce a useful message. If a Carbon user currently uses the now-deprecated form TextInput.PasswordInput, they receive the following warning message: "Warning: The PasswordInput field has been deprecated on the undefined object. Please import and use the field directly." The word "undefined" appears in that message because TextInput does not currently have displayName set on it.

Is this issue related to a specific component?

Yes, quite a lot of them. The following components DO have a displayName set currently. All the other components would be candidates to have displayName set on them.

  • Breadcrumb
  • BreadcrumbItem
  • Button
  • ButtonSet
  • Checkbox
  • TableHeader
  • TableToolbarAction
  • Dropdown
  • InlineCheckbox
  • InlineLoading
  • ListBox
  • ListBoxMenu
  • MultiSelect
  • NumberInput
  • OverflowMenu
  • RadioButton
  • Select
  • Switch
  • TextArea
  • Tooltip
  • HeaderGlobalAction
  • HeaderMenu
  • HeaderPanel
  • SideNavMenu

Only two components currently use deprecateFieldOnObject, and they are:

  • MultiSelect -- this has displayName set
  • TextInput -- this does not

What did you expect to happen? What happened instead? What would you like to
see changed?

At least TextInput should have a displayName set so that the deprecation message is shown correctly. Some thought should then be given as to whether some other, or maybe all other, components should have displayName set systematically.

What browser are you working in?

n/a

What version of the Carbon Design System are you using?

10.41.0

@joshblack
Copy link
Contributor

@dcwarwick I believe the helper uses Component.name as a fallback but that components that use React.forwardRef won't have a name defined (or displayName). Definitely makes sense to add in displayName for components that use forwardRef and this helper 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: react carbon-components-react type: bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants