@mapbox/react-click-to-select

2.2.1 • Public • Published

react-click-to-select

A React component that selects the text / elements contained within when they're clicked.

npm npm license

install

npm install --save @mapbox/react-click-to-select

use

<ClickToSelect>
  this text will be selected when clicked
</ClickToSelect>

By default ClickToSelect contains the children within a span element, but you can use a div instead:

<ClickToSelect containerElement="div">
  <p>
    this text will be selected when clicked
  </p>
</ClickToSelect>

You can pass a function that will be called when text is selected. This is useful for doing things like showing a tooltip with a prompt to copy.

<ClickToSelect onSelect={myFunc}>
  <p>
    this text will be selected when clicked
  </p>
</ClickToSelect>

This avoids React warnings:

validateDOMNesting(...): <div> cannot appear as a descendant of <p>.

Package Sidebar

Install

npm i @mapbox/react-click-to-select

Weekly Downloads

1,304

Version

2.2.1

License

ISC

Unpacked Size

7.37 kB

Total Files

5

Last publish

Collaborators

  • mbx-npm-ci-production
  • mbx-npm-ci-staging
  • mbx-npm-advanced-actions-production
  • mbx-npm-advanced-actions-staging
  • mbx-npm-09-production
  • mbx-npm-08-production
  • mbx-npm-07-production
  • mbx-npm-06-production
  • mbx-npm-05-production
  • mbx-npm-04-production
  • mbx-npm-03-production
  • mbx-npm-02-production
  • mbx-npm-01-production
  • mbx-npm-02-staging
  • mapbox-npm-01
  • mapbox-npm-02
  • mapbox-npm-07
  • mapbox-npm-03
  • mapbox-npm-04
  • mapbox-npm-09
  • mapbox-npm-05
  • mapbox-npm-06
  • mapbox-npm-08
  • mapbox-npm-advanced-actions
  • mapbox-npm-ci
  • mapbox-npm
  • mapbox-admin
  • mapbox-machine-user