Socket
Socket
Sign inDemoInstall

react-editable-label

Package Overview
Dependencies
299
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-editable-label

A simple React component for switching between a text label and a text input


Version published
Weekly downloads
1.4K
decreased by-35.26%
Maintainers
1
Install size
19.4 MB
Created
Weekly downloads
 

Readme

Source

EditableLabel

A simple React component for switching between a text label and a text input.

Clicking on the text label switches the label to a text input. A loss of focus on the text input will switch back to the text label and save the text changes.

An ESC key press will switch from text input back to label and discard any changes made to the text in the input.

An ENTER key press will switch from text input back to label and save any changes made.

When a save is triggered, the save function passed in as a prop is called with the current value of the input.

Label view

Input view

Table of Contents

  • EditableLabel

Installation

$ npm install react-editable-label $ yarn add react-editable-label

Usage

The EditableLabel object requires two props:

  • initialValue which is the initial text to display
  • save which is the function called when the text is updated.

Optional props:

  • labelClass which is added to the className of the label <span> tag.
  • inputClass which is added to the className of the text <input> tag.
  • inputName which is used for the name attribute of the text <input> tag.
  • inputId which is used for the id attribute of the text <input> tag.
  • disableKeys which disables the keyPress handler.

Example:

import React from 'react';
import {render} from 'react-dom';

import EditableLabel from 'react-editable-label';

const App = () => {
    return (
        <>
            <p>Hello!</p>
            <EditableLabel
                initialValue={'World'}
                save={value => {
                    console.log(`Saving '${value}'`);
                }}
            />
        </>
    );
}

let app = document.getElementById('app');

if (app) {
    render(<App/>, app);
}

FAQs

Last updated on 22 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc