Skip to content

Render prop callback function to provide text selection for text inputs, textarea's, etc.

Notifications You must be signed in to change notification settings

jonstuebe/react-text-selection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Text Selection

Render prop callback function to provide text selection for text inputs, textarea's, etc. Includes UMD build

Install

npm i -s @jonstuebe/react-text-selection

Usage

import React from "react";
import TextSelection from "@jonstuebe/react-text-selection";

const App = () => (
  <div>
    <TextSelection>
      {({ eventProps, selectionStart, selectionEnd }) => (
        <div>
          <p>
            {selectionStart}/{selectionEnd}
          </p>
          <textarea className="form-control" {...eventProps} />
        </div>
      )}
    </TextSelection>
  </div>
);

Codepen Example

https://codepen.io/jonstuebe/pen/zpBwrL?editors=0010

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
IE10, IE11, Edge last 4 versions last 4 versions last 4 versions

About

Render prop callback function to provide text selection for text inputs, textarea's, etc.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published