Skip to content
Related Articles

Related Articles

Improve Article

React Desktop macOS TextInput Component

  • Last Updated : 30 May, 2021
Geek Week

React Desktop is a popular library to bring the native desktop experience to the web. This library provides macOS and Windows OS components. TextInput Component is used to allow the users to create an input text field just like the macOS Operating system has. We can use the following approach in ReactJS to use the React Desktop macOS TextInput Component.

TextInput Props:

  • centerPlaceholder: When the input is not focused, it is used to set whether the placeholder is animated and centered.
  • defaultValue: It is used to denote the default input value.
  • focusRing: Around the input, it is used to set the visibility of the focus ring.
  • hidden: It is used to set the visibility of a component.
  • icon: It is used to add an icon to the input.
  • label: It is used to add a label to the Input.
  • margin: It is used to set the outer margin of the component.
  • marginBottom: It is used to set the outer bottom margin of the component.
  • marginLeft: It is used to set the outer left margin of the component.
  • marginRight: It is used to set the outer right margin of the component.
  • marginTop: It is used to set the outer top margin of the component.
  • onChange: It is a callback function that is triggered when the input is changed.
  • onEnter: It is a callback function that is triggered when the enter key is pressed.
  • placeholder: It is used to add a placeholder to the input.
  • rounded: It is used to set the roundness of the input border.
  • size: It is used to set the component font size.
  • value: It is used to set the input value.
  • width: It is used to set the component width.
  • password: It is used to set the input type to password.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:

    npx create-react-app foldername
  • Step 2: After creating your project folder i.e. foldername, move to it using the following command:



    cd foldername
  • Step 3: After creating the ReactJS application, Install the required module using the following command:

    npm install react-desktop

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React from 'react'
import { TextInput } from 'react-desktop/macOs';
  
export default function App() {
  return (
    <div style={{
      display: 'block', width: 700, paddingLeft: 30
    }}>
      <h4>React Desktop macOS TextInput Component</h4>
      <TextInput
        color="white"
        width="300"
        label="Enter your Name"
        placeholder="Enter your Name"
        onChange={(e)=> { console.log(e)}}
      />
    </div>
  );
}

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://reactdesktop.js.org/docs/mac-os/text-input




My Personal Notes arrow_drop_up
Recommended Articles
Page :