Friday, October 17, 2025
HomeLanguagesReact Desktop macOS SegmentedControl Component

React Desktop macOS SegmentedControl Component

React Desktop is a popular library to bring the native desktop experience to the web. This library provides macOS and Windows OS components. A SegmentedControl component is a linear set of two or more segments where each of which functions as a mutually exclusive button. We can use the following approach in ReactJS to use the React Desktop macOS SegmentedControl Component.

SegmentedControl Props:

  • box: It is used to indicate whether the item is in a box or not.
  • height: It is used to set component height.
  • hidden: It is used to set the component visibility.
  • 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.
  • width: It is used to set components width.

SegmentedControlItem Props:

  • title: It is used to set the title for the item.
  • onSelect: It is a callback function that is triggered on select of an item.
  • selected: It is used to indicate whether the item is selected or not.

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, { useState } from 'react'
import { SegmentedControl, SegmentedControlItem } from 'react-desktop/macOs';
  
export default function App() {
  
  // Our State object
  const [currentSelection, setCurrentSelection] = useState(1)
  
  return (
    <div style={{
      display: 'block', width: 700, paddingLeft: 30
    }}>
      <h4>React-Desktop macOS SegmentedControl Component</h4>
      <SegmentedControl box>
        <SegmentedControlItem
          key={1}
          title={"TAB 1"}
          selected={currentSelection === 1}
          onSelect={() => setCurrentSelection(1)}
        >
          Sample Text 1
        </SegmentedControlItem>
        <SegmentedControlItem
          key={2}
          title={"TAB 2"}
          selected={currentSelection === 2}
          onSelect={() => setCurrentSelection(2)}
        >
          Sample Text 2
        </SegmentedControlItem>
      </SegmentedControl>
    </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/segmented-control

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS