[Feature Request] For web renders, let `Icon` and `Chip` render as `<button>` only if it needs to be clickable

Open
#3,888 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
react, react-native
Domain
frontend

Research direction

Start by tracing the web-rendering paths for Icon, Chip, and Button and reproduce the validateDOMNesting warning described in the issue. Compare behavior with and without onPress or related callbacks; done means non-clickable components no longer create nested button elements while clickable behavior remains available.

Written by the indexing model from the issue text.

Description

Needs Triage

Is your feature request related to a problem? Please Describe.

Please refer to #3857

Tl;dr: Button with underlying Icon and Chip with underlying Icon causes validateDOMNesting check to fail for web renders because of nested <button>.

Describe the solution you'd like

To mitigate this, I propose the following changes:

  1. Icon need not behave as an HTML <button> if there are no onPress or related callbacks defined.
  2. As an extension to the above: Icon should not allow onPress or related callbacks in case it is used as a child component of a Button
  3. [Optional, but I think this is good] Chip need not behave as a Button because according to the docs: "Chips are compact elements that represent an input, attribute, or action. They may display text, icons, or both". My understanding is that they can also be used as "discrete labels/tags" to associate some sort of metadata (similar to "Labels" in Jira or "Multi-Select Tags" in Notion). In that case, Chip can have a clickable Icon.

Describe alternatives you've considered

<Icon.Button> from react-native-vector-icons conditionally be a functional replacement to <Button icon={}>, but it is less flexible.

Additional context

Dominant language
MDX
Stars
25.9k
Forks
4.7k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from react-native-elements/react-native-elements

All issues in react-native-elements/react-native-elements

Similar issues

More Web Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.