본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

ion-segment

원문 보기 위키 갱신

세그먼트 컨트롤(segmented control)이라고도 불리는 관련 버튼들의 그룹을 가로 한 줄로 표시하는 컴포넌트예요. 툴바 안이나 메인 콘텐츠에 표시할 수 있습니다.

출처: 문서

본문

Encapsulation: shadow

Segment는 때로 segmented control이라고도 불리는 관련 버튼들의 그룹을 가로 한 줄로 표시해요. 툴바 안이나 메인 콘텐츠에 표시할 수 있습니다.

그 기능은 탭과 비슷합니다. 하나를 선택하면 나머지가 모두 선택 해제돼요. Segment는 콘텐츠 안에서 서로 다른 뷰 사이를 전환하는 데 유용합니다. 컨트롤을 클릭했을 때 페이지 사이를 이동해야 한다면 segment 대신 탭을 사용해야 해요.

Basic Usage

Segment는 각 버튼에 value 프로퍼티가 있는 segment buttons으로 구성됩니다. segment에 value 프로퍼티를 설정해 어떤 버튼의 값과 일치시키면 그 버튼이 선택됩니다. segment를 비활성화해 사용자가 상호작용하지 못하게 할 수도 있어요.

JavaScript

<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

<ion-segment disabled="true" value="disabled">
  <ion-segment-button value="disabled">
    <ion-label>Disabled</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

Angular

src/app/example.component.html

<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

<ion-segment [disabled]="true" value="disabled">
  <ion-segment-button value="disabled">
    <ion-label>Disabled</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton],
})
export class ExampleComponent {}

React

import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/react';

function Example() {
  return (
    <>
      <IonSegment value="default">
        <IonSegmentButton value="default">
          <IonLabel>Default</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>

      <IonSegment disabled={true} value="disabled">
        <IonSegmentButton value="disabled">
          <IonLabel>Disabled</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-segment value="default">
    <ion-segment-button value="default">
      <ion-label>Default</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>

  <ion-segment :disabled="true" value="disabled">
    <ion-segment-button value="disabled">
      <ion-label>Disabled</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/vue';
</script>

Scrollable Segments

Segment는 기본적으로 스크롤할 수 없어요. 각 segment 버튼은 고정된 너비를 가지며, 그 너비는 segment 버튼 수를 화면 너비로 나누어 결정됩니다. 이 덕분에 스크롤할 필요 없이 각 segment 버튼을 화면에 표시할 수 있어요. 그 결과로 라벨이 긴 일부 segment 버튼은 잘릴 수 있습니다. 이를 피하려면 더 짧은 라벨을 사용하거나, scrollable 프로퍼티를 true로 설정해 스크롤 가능한 segment로 바꾸는 것을 권장합니다. 그러면 segment가 가로로 스크롤되지만 각 segment 버튼은 가변 너비를 가질 수 있게 됩니다.

JavaScript

index.html

<ion-segment scrollable="true" value="heart">
  <ion-segment-button value="home">
    <ion-icon name="home"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="heart">
    <ion-icon name="heart"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="pin">
    <ion-icon name="pin"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="star">
    <ion-icon name="star"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="call">
    <ion-icon name="call"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="globe">
    <ion-icon name="globe"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="basket">
    <ion-icon name="basket"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="barbell">
    <ion-icon name="barbell"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="trash">
    <ion-icon name="trash"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="person">
    <ion-icon name="person"></ion-icon>
  </ion-segment-button>
</ion-segment>

index.ts

import { defineCustomElements } from '@ionic/core/loader';

import { addIcons } from 'ionicons';
import { barbell, basket, call, globe, heart, home, person, pin, star, trash } from 'ionicons/icons';

/* Core CSS required for Ionic components to work properly */
import '@ionic/core/css/core.css';

/* Basic CSS for apps built with Ionic */
import '@ionic/core/css/normalize.css';
import '@ionic/core/css/structure.css';
import '@ionic/core/css/typography.css';

/* Optional CSS utils that can be commented out */
import '@ionic/core/css/padding.css';
import '@ionic/core/css/float-elements.css';
import '@ionic/core/css/text-alignment.css';
import '@ionic/core/css/text-transformation.css';
import '@ionic/core/css/flex-utils.css';
import '@ionic/core/css/display.css';

/**
 * Ionic Dark Palette
 * -----------------------------------------------------
 * For more information, please see:
 * https://ionicframework.com/docs/theming/dark-mode
 */

// import '@ionic/core/css/palettes/dark.always.css';
// import '@ionic/core/css/palettes/dark.class.css';
import '@ionic/core/css/palettes/dark.system.css';

/* Theme variables */
import './theme/variables.css';

/**
 * On Ionicons 7.2+ these icons
 * get mapped to a kebab-case key.
 * Alternatively, developers can do:
 * addIcons({ 'barbell': barbell, 'basket': basket, 'call': call, 'globe': globe,
 * 'heart': heart, 'home': home, 'person': person, 'pin': pin, 'star': star, 'trash': trash });
 */
addIcons({ barbell, basket, call, globe, heart, home, person, pin, star, trash });

defineCustomElements();

Angular

src/app/example.component.html

<ion-segment [scrollable]="true" value="heart">
  <ion-segment-button value="home">
    <ion-icon name="home"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="heart">
    <ion-icon name="heart"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="pin">
    <ion-icon name="pin"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="star">
    <ion-icon name="star"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="call">
    <ion-icon name="call"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="globe">
    <ion-icon name="globe"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="basket">
    <ion-icon name="basket"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="barbell">
    <ion-icon name="barbell"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="trash">
    <ion-icon name="trash"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="person">
    <ion-icon name="person"></ion-icon>
  </ion-segment-button>
</ion-segment>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonIcon, IonSegment, IonSegmentButton } from '@ionic/angular';

import { addIcons } from 'ionicons';
import { barbell, basket, call, globe, heart, home, person, pin, star, trash } from 'ionicons/icons';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonIcon, IonSegment, IonSegmentButton],
})
export class ExampleComponent {
  constructor() {
    /**
     * Any icons you want to use in your application
     * can be registered in app.component.ts and then
     * referenced by name anywhere in your application.
     */
    addIcons({ barbell, basket, call, globe, heart, home, person, pin, star, trash });
  }
}

React

import React from 'react';
import { IonIcon, IonSegment, IonSegmentButton } from '@ionic/react';
import { home, heart, pin, star, call, globe, basket, barbell, trash, person } from 'ionicons/icons';

function Example() {
  return (
    <IonSegment scrollable={true} value="heart">
      <IonSegmentButton value="home">
        <IonIcon icon={home}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="heart">
        <IonIcon icon={heart}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="pin">
        <IonIcon icon={pin}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="star">
        <IonIcon icon={star}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="call">
        <IonIcon icon={call}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="globe">
        <IonIcon icon={globe}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="basket">
        <IonIcon icon={basket}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="barbell">
        <IonIcon icon={barbell}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="trash">
        <IonIcon icon={trash}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="person">
        <IonIcon icon={person}></IonIcon>
      </IonSegmentButton>
    </IonSegment>
  );
}
export default Example;

Vue

<template>
  <ion-segment :scrollable="true" value="heart">
    <ion-segment-button value="home">
      <ion-icon :icon="home"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="heart">
      <ion-icon :icon="heart"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="pin">
      <ion-icon :icon="pin"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="star">
      <ion-icon :icon="star"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="call">
      <ion-icon :icon="call"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="globe">
      <ion-icon :icon="globe"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="basket">
      <ion-icon :icon="basket"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="barbell">
      <ion-icon :icon="barbell"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="trash">
      <ion-icon :icon="trash"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="person">
      <ion-icon :icon="person"></ion-icon>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonIcon, IonSegment, IonSegmentButton } from '@ionic/vue';
  import { home, heart, pin, star, call, globe, basket, barbell, trash, person } from 'ionicons/icons';
</script>

Segments in Toolbars

JavaScript

<ion-header>
  <ion-toolbar>
    <ion-segment value="all">
      <ion-segment-button value="all">
        <ion-label>All</ion-label>
      </ion-segment-button>
      <ion-segment-button value="favorites">
        <ion-label>Favorites</ion-label>
      </ion-segment-button>
    </ion-segment>
  </ion-toolbar>
</ion-header>

Angular

src/app/example.component.html

<ion-header>
  <ion-toolbar>
    <ion-segment value="all">
      <ion-segment-button value="all">
        <ion-label>All</ion-label>
      </ion-segment-button>
      <ion-segment-button value="favorites">
        <ion-label>Favorites</ion-label>
      </ion-segment-button>
    </ion-segment>
  </ion-toolbar>
</ion-header>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonHeader, IonLabel, IonSegment, IonSegmentButton, IonToolbar } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonHeader, IonLabel, IonSegment, IonSegmentButton, IonToolbar],
})
export class ExampleComponent {}

React

import React from 'react';
import { IonHeader, IonLabel, IonSegment, IonSegmentButton, IonTitle, IonToolbar } from '@ionic/react';

function Example() {
  return (
    <IonHeader>
      <IonToolbar>
        <IonSegment value="all">
          <IonSegmentButton value="all">
            <IonLabel>All</IonLabel>
          </IonSegmentButton>
          <IonSegmentButton value="favorites">
            <IonLabel>Favorites</IonLabel>
          </IonSegmentButton>
        </IonSegment>
      </IonToolbar>
    </IonHeader>
  );
}
export default Example;

Vue

<template>
  <ion-header>
    <ion-toolbar>
      <ion-segment value="all">
        <ion-segment-button value="all">
          <ion-label>All</ion-label>
        </ion-segment-button>
        <ion-segment-button value="favorites">
          <ion-label>Favorites</ion-label>
        </ion-segment-button>
      </ion-segment>
    </ion-toolbar>
  </ion-header>
</template>

<script setup lang="ts">
  import { IonHeader, IonLabel, IonSegment, IonSegmentButton, IonTitle, IonToolbar } from '@ionic/vue';
</script>

Swipeable Segments

각각의 segment button은 segment가 활성화될 때 표시되는 segment content 요소와 연결할 수 있어요. 이 방식을 사용하면 각 segment의 콘텐츠를 스와이프하거나 스크롤해 넘길 수 있고, segment는 현재 보이는 콘텐츠를 반영하도록 업데이트됩니다.

Warning

스와이프 가능한 segment를 사용할 때 ion-segment에 초기 value가 할당되지 않으면, segment는 첫 번째 segment button의 값으로 기본 설정됩니다. 세그먼트 버튼은 스와이프 가능한 segment와 함께 사용할 때 비활성화할 수 없어요.

JavaScript

<ion-segment>
  <ion-segment-button value="first" content-id="first">
    <ion-label>First</ion-label>
  </ion-segment-button>
  <ion-segment-button value="second" content-id="second">
    <ion-label>Second</ion-label>
  </ion-segment-button>
  <ion-segment-button value="third" content-id="third">
    <ion-label>Third</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment-view>
  <ion-segment-content id="first">First</ion-segment-content>
  <ion-segment-content id="second">Second</ion-segment-content>
  <ion-segment-content id="third">Third</ion-segment-content>
</ion-segment-view>

<style>
  ion-segment-view {
    height: 150px;
  }

  ion-segment-content {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  ion-segment-content:nth-of-type(1) {
    background: lightpink;
  }
  ion-segment-content:nth-of-type(2) {
    background: lightblue;
  }
  ion-segment-content:nth-of-type(3) {
    background: lightgreen;
  }
</style>

Angular

src/app/example.component.html

<ion-segment>
  <ion-segment-button value="first" content-id="first">
    <ion-label>First</ion-label>
  </ion-segment-button>
  <ion-segment-button value="second" content-id="second">
    <ion-label>Second</ion-label>
  </ion-segment-button>
  <ion-segment-button value="third" content-id="third">
    <ion-label>Third</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment-view>
  <ion-segment-content id="first">First</ion-segment-content>
  <ion-segment-content id="second">Second</ion-segment-content>
  <ion-segment-content id="third">Third</ion-segment-content>
</ion-segment-view>

src/app/example.component.css

ion-segment-view {
  height: 150px;
}

ion-segment-content {
  display: flex;
  align-items: center;
  justify-content: center;
}
ion-segment-content:nth-of-type(1) {
  background: lightpink;
}
ion-segment-content:nth-of-type(2) {
  background: lightblue;
}
ion-segment-content:nth-of-type(3) {
  background: lightgreen;
}

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView],
})
export class ExampleComponent {}

React

src/main.css

ion-segment-view {
  height: 150px;
}

ion-segment-content {
  display: flex;
  align-items: center;
  justify-content: center;
}
ion-segment-content:nth-of-type(1) {
  background: lightpink;
}
ion-segment-content:nth-of-type(2) {
  background: lightblue;
}
ion-segment-content:nth-of-type(3) {
  background: lightgreen;
}

src/main.tsx

import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/react';

import './main.css';

function Example() {
  return (
    <>
      <IonSegment value="first">
        <IonSegmentButton value="first" contentId="first">
          <IonLabel>First</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="second" contentId="second">
          <IonLabel>Second</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="third" contentId="third">
          <IonLabel>Third</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegmentView>
        <IonSegmentContent id="first">First</IonSegmentContent>
        <IonSegmentContent id="second">Second</IonSegmentContent>
        <IonSegmentContent id="third">Third</IonSegmentContent>
      </IonSegmentView>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-segment>
    <ion-segment-button value="first" content-id="first">
      <ion-label>First</ion-label>
    </ion-segment-button>
    <ion-segment-button value="second" content-id="second">
      <ion-label>Second</ion-label>
    </ion-segment-button>
    <ion-segment-button value="third" content-id="third">
      <ion-label>Third</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment-view>
    <ion-segment-content id="first">First</ion-segment-content>
    <ion-segment-content id="second">Second</ion-segment-content>
    <ion-segment-content id="third">Third</ion-segment-content>
  </ion-segment-view>
</template>

<style>
  ion-segment-view {
    height: 150px;
  }

  ion-segment-content {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  ion-segment-content:nth-of-type(1) {
    background: lightpink;
  }
  ion-segment-content:nth-of-type(2) {
    background: lightblue;
  }
  ion-segment-content:nth-of-type(3) {
    background: lightgreen;
  }
</style>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/vue';
</script>

Theming

Colors

JavaScript

<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="primary" value="primary">
  <ion-segment-button value="primary">
    <ion-label>Primary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="secondary" value="secondary">
  <ion-segment-button value="secondary">
    <ion-label>Secondary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="tertiary" value="tertiary">
  <ion-segment-button value="tertiary">
    <ion-label>Tertiary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="success" value="success">
  <ion-segment-button value="success">
    <ion-label>Success</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="warning" value="warning">
  <ion-segment-button value="warning">
    <ion-label>Warning</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="danger" value="danger">
  <ion-segment-button value="danger">
    <ion-label>Danger</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="light" value="light">
  <ion-segment-button value="light">
    <ion-label>Light</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="medium" value="medium">
  <ion-segment-button value="medium">
    <ion-label>Medium</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="dark" value="dark">
  <ion-segment-button value="dark">
    <ion-label>Dark</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

Angular

src/app/example.component.html

<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="primary" value="primary">
  <ion-segment-button value="primary">
    <ion-label>Primary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="secondary" value="secondary">
  <ion-segment-button value="secondary">
    <ion-label>Secondary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="tertiary" value="tertiary">
  <ion-segment-button value="tertiary">
    <ion-label>Tertiary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="success" value="success">
  <ion-segment-button value="success">
    <ion-label>Success</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="warning" value="warning">
  <ion-segment-button value="warning">
    <ion-label>Warning</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="danger" value="danger">
  <ion-segment-button value="danger">
    <ion-label>Danger</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="light" value="light">
  <ion-segment-button value="light">
    <ion-label>Light</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="medium" value="medium">
  <ion-segment-button value="medium">
    <ion-label>Medium</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="dark" value="dark">
  <ion-segment-button value="dark">
    <ion-label>Dark</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton],
})
export class ExampleComponent {}

React

import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/react';

function Example() {
  return (
    <>
      <IonSegment value="default">
        <IonSegmentButton value="default">
          <IonLabel>Default</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="primary" value="primary">
        <IonSegmentButton value="primary">
          <IonLabel>Primary</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="secondary" value="secondary">
        <IonSegmentButton value="secondary">
          <IonLabel>Secondary</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="tertiary" value="tertiary">
        <IonSegmentButton value="tertiary">
          <IonLabel>Tertiary</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="success" value="success">
        <IonSegmentButton value="success">
          <IonLabel>Success</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="warning" value="warning">
        <IonSegmentButton value="warning">
          <IonLabel>Warning</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="danger" value="danger">
        <IonSegmentButton value="danger">
          <IonLabel>Danger</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="light" value="light">
        <IonSegmentButton value="light">
          <IonLabel>Light</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="medium" value="medium">
        <IonSegmentButton value="medium">
          <IonLabel>Medium</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="dark" value="dark">
        <IonSegmentButton value="dark">
          <IonLabel>Dark</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-segment value="default">
    <ion-segment-button value="default">
      <ion-label>Default</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="primary" value="primary">
    <ion-segment-button value="primary">
      <ion-label>Primary</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="secondary" value="secondary">
    <ion-segment-button value="secondary">
      <ion-label>Secondary</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="tertiary" value="tertiary">
    <ion-segment-button value="tertiary">
      <ion-label>Tertiary</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="success" value="success">
    <ion-segment-button value="success">
      <ion-label>Success</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="warning" value="warning">
    <ion-segment-button value="warning">
      <ion-label>Warning</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="danger" value="danger">
    <ion-segment-button value="danger">
      <ion-label>Danger</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="light" value="light">
    <ion-segment-button value="light">
      <ion-label>Light</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="medium" value="medium">
    <ion-segment-button value="medium">
      <ion-label>Medium</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="dark" value="dark">
    <ion-segment-button value="dark">
      <ion-label>Dark</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/vue';
</script>

CSS Custom Properties

JavaScript

<style>
  ion-segment {
    --background: #54dc98;
  }
</style>

<ion-segment value="custom">
  <ion-segment-button value="custom">
    <ion-label>Custom</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

Angular

src/app/example.component.html

<ion-segment value="custom">
  <ion-segment-button value="custom">
    <ion-label>Custom</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

src/app/example.component.css

ion-segment {
  --background: #54dc98;
}

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton],
})
export class ExampleComponent {}

React

src/main.css

ion-segment {
  --background: #54dc98;
}

src/main.tsx

import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/react';

import './main.css';

function Example() {
  return (
    <>
      <IonSegment value="custom">
        <IonSegmentButton value="custom">
          <IonLabel>Custom</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-segment value="custom">
    <ion-segment-button value="custom">
      <ion-label>Custom</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/vue';
</script>

<style>
  ion-segment {
    --background: #54dc98;
  }
</style>

Accessibility

Keyboard Interactions

이 컴포넌트는 ion-segment-button 요소 사이를 탐색하고 선택하기 위한 완전한 키보드 지원을 제공해요. 기본적으로 키보드 탐색은 ion-segment-button 요소에만 포커스를 주지만, selectOnFocus 프로퍼티를 사용해 포커스 시 선택까지 되도록 할 수 있습니다. 다음 표는 각 키가 무엇을 하는지 자세히 설명해요:

Key Description
ArrowRight 다음 포커스 가능한 요소에 포커스를 줍니다.
ArrowLeft 이전 포커스 가능한 요소에 포커스를 줍니다.
Home 첫 번째 포커스 가능한 요소에 포커스를 줍니다.
End 마지막 포커스 가능한 요소에 포커스를 줍니다.
Space or Enter 현재 포커스된 요소를 선택합니다.

Interfaces

SegmentChangeEventDetail

interface SegmentChangeEventDetail {
  value?: string;
}

SegmentCustomEvent

필수는 아니지만, 이 컴포넌트에서 발생하는 Ionic 이벤트에 대해 더 강력한 타입을 제공하려면 CustomEvent 인터페이스 대신 이 인터페이스를 사용할 수 있어요.

interface SegmentCustomEvent extends CustomEvent {
  target: HTMLIonSegmentElement;
  detail: SegmentChangeEventDetail;
}

Properties

color

Description: 애플리케이션의 컬러 팔레트에서 사용할 색상이에요. 기본 옵션은 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", "dark"입니다. 색상에 대한 자세한 내용은 theming을 참고하세요.

Attribute: color

Type: "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined

Default: undefined

disabled

Description: true로 설정하면 사용자가 segment와 상호작용할 수 없어요.

Attribute: disabled

Type: boolean

Default: false

mode

Description: 모드는 어떤 플랫폼 스타일을 사용할지 결정해요. 이 값은 초기화 중에 한 번 설정되며 초기 렌더 후 값을 변경해도 업데이트되지 않는 가상 프로퍼티예요.

Attribute: mode

Type: "ios" | "md"

Default: undefined

scrollable

Description: true로 설정하면 segment 버튼이 넘치고 사용자가 스와이프해 볼 수 있어요. 또한 버튼 사이에서 표시기를 드래그해 숨겨진 버튼을 보게 하는 제스처는 비활성화됩니다.

Attribute: scrollable

Type: boolean

Default: false

selectOnFocus

Description: true로 설정하면 키보드로 ion-segment-button에 탐색할 때 요소가 포커스되면서 선택됩니다. false로 설정하면 키보드 탐색은 ion-segment-button 요소에 포커스만 줄 뿐입니다.

Attribute: select-on-focus

Type: boolean

Default: false

swipeGesture

Description: true로 설정하면 사용자가 segment 버튼 사이를 스와이프해 활성화할 수 있어요.

Attribute: swipe-gesture

Type: boolean

Default: true

value

Description: segment의 값이에요.

Attribute: value

Type: number | string | undefined

Default: undefined

Events

Name Description Bubbles
ionChange value 프로퍼티가 변경되고 드래그하던 포인터가 ion-segment에서 놓였을 때 발생해요. value 프로퍼티를 프로그래밍 방식으로 설정할 때는 이 이벤트가 발생하지 않아요. true

Methods

이 컴포넌트에는 공개 메서드가 없어요.

CSS Shadow Parts

이 컴포넌트에는 사용할 수 있는 CSS shadow part가 없어요.

CSS Custom Properties

iOS

Name Description
--background segment 버튼의 배경색(Background of the segment button)

MD

Name Description
--background segment 버튼의 배경색(Background of the segment button)

Slots

Name Description
기본 슬롯(The default slot)

더 알아보기 (Learn more)

ion-segment는 관련 버튼들을 가로로 나열해 한 번에 하나만 선택되게 하는 세그먼트 컨트롤이에요. 각 옵션 버튼은 ion-segment-button으로 만들고, scrollable로 넘침을 허용하거나 swipeGesture/segment content로 스와이프 전환까지 구성할 수 있어요.