Open In App

React Desktop macOS SearchField Component

Last Updated : 30 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

React Desktop is a popular library to bring the native desktop experience to the web. This library provides macOS and Windows OS components. SearchField Component is used to allow the users to create a search field just like the macOS Operating system has, it helps users in searching operation. We can use the following approach in ReactJS to use the React Desktop macOS SearchField Component.

SearchField Props:

  • cancel:  It defines that the cancel button should visible or not.
  • 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.
  • onCancel: It is a callback function that is triggered when the user presses the cancel button.
  • 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.

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 { SearchField } from 'react-desktop/macOs';
  
export default function App() {
  return (
    <div style={{
      display: 'block', width: 400, paddingLeft: 30
    }}>
      <h4>React Desktop macOS SearchField Component</h4>
      <SearchField
        label="Search"
        placeholder="Search"
        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/search-field



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads