• Stars
    star
    1,576
  • Rank 28,770 (Top 0.6 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React component for a div with editable contents

react-contenteditable

React component for a div with editable contents

Build Status download count bundle size license

Install

npm install react-contenteditable

Usage

import React from 'react'
import ContentEditable from 'react-contenteditable'

class MyComponent extends React.Component {
  constructor() {
    super()
    this.contentEditable = React.createRef();
    this.state = {html: "<b>Hello <i>World</i></b>"};
  };

  handleChange = evt => {
    this.setState({html: evt.target.value});
  };

  render = () => {
    return <ContentEditable
              innerRef={this.contentEditable}
              html={this.state.html} // innerHTML of the editable div
              disabled={false}       // use true to disable editing
              onChange={this.handleChange} // handle innerHTML change
              tagName='article' // Use a custom HTML tag (uses a div by default)
            />
  };
};

Available props

prop description type
innerRef element's ref attribute Object | Function
html required: innerHTML of the editable element String
disabled use true to disable editing Boolean
onChange called whenever innerHTML changes Function
onBlur called whenever the html element is blurred Function
onFocus event fires when an element has received focus Function
onKeyUp called whenever a key is released Function
onKeyDown called whenever a key is pressed Function
className the element's CSS class String
style a collection of CSS properties to apply to the element Object

Known Issues

If you are using hooks, please see this issue. Using this component with useState doesn't work, but you can still use useRef :

const text = useRef('');

const handleChange = evt => {
    text.current = evt.target.value;
};

const handleBlur = () => {
    console.log(text.current);
};

return <ContentEditable html={text.current} onBlur={handleBlur} onChange={handleChange} />

Examples

You can try react-contenteditable right from your browser to see if it fits your project's needs:

More Repositories

1

whitebophir

Online collaborative Whiteboard that is simple, free, easy to use and to deploy
JavaScript
1,720
star
2

dezoomify

Dezoomify is a web application to download zoomable images from museum websites, image galleries, and map viewers. Many different zoomable image technologies are supported.
JavaScript
581
star
3

dezoomify-rs

Zoomable image downloader for Google Arts & Culture, Zoomify, IIIF, and others
Rust
437
star
4

marshmallow_dataclass

Automatic generation of marshmallow schemas from dataclasses.
Python
435
star
5

bad_json_parsers

Exposing problems in json parsers of several programming languages.
Python
363
star
6

sanipasse

Vérificateur de passe sanitaire open-source
Svelte
176
star
7

json_in_type

Fast json encoder in rust, that encodes the structure of JSON values in their types
Rust
82
star
8

custom_error

Define custom errors without boilerplate using the custom_error! macro.
Rust
70
star
9

pagelabels-py

Python library to manipulate PDF page labels
Python
55
star
10

highs-js

Javascript linear programming library
JavaScript
44
star
11

salesman.js

Solves the traveling salesman problem using simulated annealing.
JavaScript
43
star
12

linear-solve

Small javascript library to solve a system of linear equations, invert a matrix, and nothing more.
JavaScript
38
star
13

bloomfilter

Simplistic (but fast) java implementation of a bloom filter.
Java
37
star
14

bin2png

Embed binary data inside an HTML file in an efficient way.
JavaScript
34
star
15

mandelbrot

A mandelbrot fractal viewer in javascript using svelte
JavaScript
34
star
16

dezoomify-extension

A browser extension to detect zoomable images in web pages and downloading them with dezoomify
JavaScript
33
star
17

TPCH-sqlite

SQLite TPCH database
Shell
32
star
18

Sensitive-Topic-History-Quiz

This is the only place where me, the human is talking. All of the files in this repo were generated by ChatGPT. They required hours of interactions with the language model to make it fix its own bugs, and create coherent components, but I am very proud of the result.
JavaScript
31
star
19

fast_array_intersect

The fastest javascript array intersection function
JavaScript
18
star
20

eml2csv

Convert a collection of eml files to CSV
Python
17
star
21

SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
Rust
17
star
22

historique-velib-opendata

Historique des données d'occupation de stations vélib' (publiées en opendata)
Python
13
star
23

dia2code

Dia2Code is a small utility used to generate code from a Dia diagram.
C
13
star
24

musreact

Mustache template to react component compiler
JavaScript
12
star
25

graham-fast

Graham scan implementation in javascript
JavaScript
10
star
26

html2unicode

Node module for transforming HTML into unicode
JavaScript
10
star
27

wordsearch

Search words by regex
Svelte
9
star
28

seamcarving

Seam carving implemented in rust
Rust
9
star
29

ZIF

zif file format documantation and tools
JavaScript
9
star
30

samsung-email-password-decrypt

Decrypt encrypted passwords in EmailProvider.db on samsung phones.
Java
9
star
31

dezoom.sh

Download and assemble tiled images. Dezoomify for bash. Depends on imagemagick
Shell
8
star
32

github-sloc

Firefox extension that prints the number of lines of code of a project on project pages on github.
JavaScript
8
star
33

wikipedia-externallinks-fast-extraction

Fast extraction of all external links from wikipedia
Rust
8
star
34

ophirofox

Une extension pour navigateurs qui permet de lire les articles du monde.fr sur son compte europresse ENS
JavaScript
8
star
35

lagrange-cpp

Lagrange interpolation polynomials in C++11
C++
7
star
36

gnome-keyboard-backlight-menu

Set the keyboard backlight brightness with a slider in gnome shell's system menu.
JavaScript
7
star
37

rectangle-overlap

Fastly compute the intersection of two rectangles.
TypeScript
6
star
38

pyformat-challenge

Python format string vulnerability exploitation challenge
Python
6
star
39

memoization

Straightforward implementation of memoization in javascript
JavaScript
6
star
40

reg

rÊg is a simple grid game
JavaScript
5
star
41

dezoomify-py

Fork of https://sourceforge.net/projects/dezoomify/
Python
5
star
42

haskell-exercises

Exercices pour apprendre le haskell
Haskell
4
star
43

GoodChat

Simple chat application with ES6 + Vue.js + CouchDB
JavaScript
4
star
44

kdsearch

Search k-dimensional datasets efficiently using KDTrees
Python
4
star
45

secured-file-transfer

Secured file transfer implemented in nodeJS.
JavaScript
4
star
46

BarcodeDetector-api-demo

A quick demo for the Barcode Detection API
HTML
4
star
47

expectation-maximization

Multivariate gaussian fit with expectation–maximization (EM) algorithm in javascript.
JavaScript
4
star
48

maya_numerals_converter

Online decimal to maya numeral converter.
HTML
4
star
49

pff-extract

pff (zoomify single-file image format) to jpeg converter
C
3
star
50

choices

Represent a choice between multiple values, using radio buttons, checkboxes, or HTML's <select> element
Elm
3
star
51

elm-rolling-list

A circular buffer implementation in Elm.
Elm
3
star
52

robots

Multi-agents system where robots go fetch materials.
HTML
2
star
53

RLE

Run-length encoding and decoding in haskell.
Haskell
2
star
54

emotions

Detect emotions from webcam images.
CSS
2
star
55

elm-jsonpseudolist

Elm Json.Decoder for javascript Array-like objects
Elm
2
star
56

multivariate-gaussian

Multivariate normal distribution density function implemented in javascript
JavaScript
2
star
57

download-book-of-kells

Shell
2
star
58

parse_wiki_text

Parse wiki text from Mediawiki into a tree of elements
Rust
2
star
59

SuperLogger

Log system information using logstash, store the information on ElasticSearch, and visualize it using Kibana.
Java
2
star
60

SearchHitIterator

Java iterator for elasticsearch scrolls
Java
2
star
61

setup-emscripten

emscripten github action
JavaScript
2
star
62

sha_hashes

Collection of sha hashes of common passwords
2
star
63

sql2json

Convert sql database dumps to JSON
Rust
2
star
64

2048.lua

lua implementation of the popular game "2048". The aim is to merge tiles until you get a 2048 tile. Original game by @gabrielecirulli on http://gabrielecirulli.github.io/2048/ .
Lua
2
star
65

csv-fill-docx

Fill docx templates with data from a csv file
JavaScript
1
star
66

c-osi

C interface to Open Solver Interface solvers for easy integration with external solvers
C++
1
star
67

lovasoa.github.io

Github pages root
HTML
1
star
68

cemantriche

Cémantriche, pour tricher à cémantix
Jupyter Notebook
1
star
69

resume

Ophir LOJKINE's resume, in the jsonresume format.
1
star
70

lsystems

Haskell implementation of l systems
Haskell
1
star
71

libepeg.js

epeg compiled to javascript. Fast jpeg thumbnailing.
C
1
star
72

doublons-js

Find duplicates files in a folder (search files with similar names). GUI application with node-webkit.
JavaScript
1
star
73

qrcode-dataset

A large dataset of partially damaged and distorted QR code images to be used for benchmarking scanning libraries and training new models
Python
1
star
74

poker

poker probabilities map
JavaScript
1
star
75

ruzzleplayer

Javascript implementation of an algorithm that plays the mobile game "ruzzle"
JavaScript
1
star
76

ophir_odt_import

Drupal module to import odt (OpenDocument) files into drupal nodes.
PHP
1
star
77

kaigit

Svelte
1
star
78

srtmove-hs

Delay .srt subtitles
Haskell
1
star
79

find-candidate-keys

Finds the candidate keys from a list of functionnal dependencies
JavaScript
1
star
80

comptes

Expenses management for friends
JavaScript
1
star
81

omodbus

OModbus is a GUI to interact with modbus devices
HTML
1
star
82

elm-fileinput

<input type="file" /> for Elm
Elm
1
star
83

elm-base-repo

Base repository containing an empty elm module, ready tobe forked.
Elm
1
star
84

dezoomify-browser

This is a small browser that automatically launches dezoomify when it meets a zoomified image. Uses node-webkit.
JavaScript
1
star
85

anylang

Type text in any alphabet. Anylang is a javascript library that converts a phonetic transcription of a text in a language to a text written in the alphabet of the target language. Currently works with hebrew (with vowels) and russian.
JavaScript
1
star
86

srtmove-js

Short javascript program with an HTML interface to move subtitles (add or remove time) to an existing srt file.
JavaScript
1
star
87

dataiku-exercise

US census visualization web application. Given as an exercise by dataiku after a job interview. I didn't get the job.
Elm
1
star