सीधे मुख्य कॉन्टेंट पर जाएँ
menumenu tanreiexpand_morecontrasttranslate
tanreiexpand_more
शुरुआत करेंWebReactSwiftUIJetpack ComposeFlutterReact Nativeप्रीसेटआपका अपना डिज़ाइन सिस्टमAI एजेंट के साथ Tanrei का इस्तेमालब्रांडडिज़ाइन टोकनडिज़ाइन सिस्टम और कस्टमाइज़ेशनTheme Studioरंगटाइपोग्राफ़ीआइकनशेपएलिवेशनमोशनइंटरैक्शन स्टेटव्यवहारलेआउटसुलभताशब्दकलर टोकनटाइप स्केल टोकनशेप टोकनएलिवेशन टोकनमोशन टोकनस्टेट टोकनस्पेस और माप के टोकनकंपोनेंटबटनमुख्य ऐक्शन बटनसेगमेंटेड बटनबटन ग्रुपमेन्यू वाला बटनटूलबारकॉपी बटनचेकबॉक्सरेडियो बटनस्विचचिपमेन्यूस्लाइडरस्लाइडर फ़ील्डकैलेंडरDateTimePickerफ़ील्ड ग्रुपरेडियो ग्रुपचेकबॉक्स ग्रुपसिलेक्टसिलेक्ट फ़ील्डमेन्यू बारफ़ाइल अपलोडफ़ाइल पिकर उन्नतड्रॉप ज़ोनटेक्स्ट इनपुट उन्नतटेक्स्ट फ़ील्डचिप फ़ील्डफ़ील्डकॉम्बोबॉक्स उन्नतकॉम्बोबॉक्स फ़ील्डनंबर इनपुट उन्नतनंबर फ़ील्डकलर इनपुट उन्नतकलर फ़ील्डवन-टाइम कोड इनपुट उन्नतवन-टाइम कोड फ़ील्डएम्बेडेड टेक्स्ट इनपुट उन्नतचैट कंपोज़रकार्डडिवाइडरमोडल लेयर उन्नतडायलॉगलिस्टलिस्ट पंक्तिबॉटम शीटसाइड शीटकैरसेलकोड ब्लॉकटेबलपॉपओवरचरणअकॉर्डियनडिस्क्रिप्शन लिस्टफ़िगरऐप शेलपेज हेडरट्री व्यूटाइमलाइनइमेज प्रीव्यूसाइज़ हैंडलसाइज़ बदलने वाला फ़्रेमस्क्रॉल एरियाबैजप्रोग्रेस इंडिकेटरमीटरनंबर टिकरलोडिंग इंडिकेटरस्नैकबारटूलटिपकीबोर्ड शॉर्टकटटैगइनलाइन कोडकॉलआउटअवतारख़ाली स्टेटटैग ग्रुपस्केलेटनफ़ाइल आइटमस्वॉचमार्की टेक्स्टटैबटैब व्यूऐप बारनेविगेशन बारनेविगेशन ड्रॉअरखोजलिंकपेजिनेशनपिछला और अगला लिंकस्टेपरब्रेडक्रंबविषय सूचीलिंक कार्डFAB मेन्यूस्थितिTanrei कैसे बनता हैयोगदानलाइसेंस और श्रेय
होमकंपोनेंटसेगमेंटेड बटन

सेगमेंटेड बटन

लोगों को दो से पाँच संबंधित विकल्पों में से एक या कई चुनने देता है, जो एक ही कंट्रोल के जुड़े हुए सेगमेंट के रूप में अगल-बग़ल बने होते हैं।

content_copyMarkdown में देखें
श्रेणी
ऐक्शन
टोकन
comp.segmented-button
स्तर
आधार

अवलोकन

Web
tanrei-segmented-button
schedule
SwiftUI
TanreiSegmentedButton
schedule
Jetpack Compose
TanreiSegmentedButton
schedule
Flutter
TanreiSegmentedButton
schedule
React Native
SegmentedButton
schedule

इससे जनरेट किया गया: docs/status/status.json, specs/segmented-button.spec.json

हर डिज़ाइन सिस्टम में नहीं

cupertino, m3-expressive-like, m3-like में शामिल, @tanrei/web/cupertino, @tanrei/web/m3-expressive-like, @tanrei/web/m3-like से रजिस्टर होता है।

tanrei में नहीं है। One choice among several is told by what it changes: tabs where it switches the content below, radio buttons where it sets a value, a button group where each button toggles on its own. इसके बजाय Tabs, Radio button, Button group इस्तेमाल करें।

जिस सिस्टम में यह नहीं है, उस पर बना प्रोडक्ट भी इसे ले सकता है: इसे अपनी लेयर में शामिल करें (आपका अपना डिज़ाइन सिस्टम) और इसका अपना मॉड्यूल इम्पोर्ट करें। तब यह आपके सिस्टम के अपने टोकन से बनता है।

"components": {
  "include": ["segmented-button"]
}
import '@tanrei/web/components/segmented-button';

एकल चयन, आइकन के साथ, सिर्फ़ आइकन

m3-like के साथ

इस्तेमाल

सेगमेंटेड बटन अपने सेगमेंट उसी तरह रखता है जैसे हर प्लैटफ़ॉर्म दोहराए जाने वाले चाइल्ड रखता है: वेब पर चाइल्ड एलिमेंट, SwiftUI पर व्यू बिल्डर के भीतर व्यू, Compose पर कॉन्टेंट लैम्ब्डा के भीतर कॉल, Flutter पर एक segments लिस्ट और React Native पर एक items ऐरे। चयन सेट का होता है, मान के आधार पर। selection बताता है कि वह एक मान है या कई।

<tanrei-segmented-button label="अवधि" value="week">
  <tanrei-segment value="day" label="दिन"></tanrei-segment>
  <tanrei-segment value="week" label="हफ़्ता"></tanrei-segment>
  <tanrei-segment value="month" label="महीना"></tanrei-segment>
</tanrei-segmented-button>

<!-- एक साथ कई। values एक प्रॉपर्टी (ऐरे) है; ऐट्रिब्यूट JSON ऐरे या स्पेस से अलग किए गए मान लेता है। -->
<tanrei-segmented-button id="days" selection="multiple" size="small" label="दिन" values="mon tue">
  <tanrei-segment value="mon" label="सोम"></tanrei-segment>
  <tanrei-segment value="tue" label="मंगल"></tanrei-segment>
  <tanrei-segment value="wed" label="बुध" disabled></tanrei-segment>
</tanrei-segmented-button>

<script type="module">
  import '@tanrei/web/components/segmented-button';
  // एलिमेंट अपना value या values ख़ुद अपडेट करता है, फिर change फ़ायर करता है।
  document.querySelector('[label="अवधि"]').addEventListener('change', (e) => showRange(e.detail.value));
  document.querySelector('#days').addEventListener('change', (e) => setDays(e.detail.values));
</script>
// डिफ़ॉल्ट सिस्टम सेगमेंटेड बटन को शामिल नहीं करता: यह m3-like, m3-expressive-like और cupertino की एंट्री में है, और /all में।
import { Segment, SegmentedButton } from '@tanrei/react/m3-like';

// एकल चयन के लिए detail { value } है, और कई के लिए { values }।
<SegmentedButton label="अवधि" value={range} onChange={(e) => 'value' in e.detail && setRange(e.detail.value)}>
  <Segment value="day" label="दिन" />
  <Segment value="week" label="हफ़्ता" />
  <Segment value="month" label="महीना" />
</SegmentedButton>

<SegmentedButton selection="multiple" label="दिन" values={days} onChange={(e) => 'values' in e.detail && setDays(e.detail.values)}>
  <Segment value="mon" label="सोम" />
  <Segment value="tue" label="मंगल" />
  <Segment value="wed" label="बुध" disabled />
</SegmentedButton>
import Tanrei

// बाइंडिंग का टाइप ही चयन है: एक के लिए ऑप्शनल मान, कई के लिए Set।
// .tag और .labelStyle को ख़ुद TanreiSegment पर लगाएँ, किसी भी दूसरे मॉडिफ़ायर से पहले।
TanreiSegmentedButton("अवधि", selection: $range) {
    TanreiSegment("दिन").tag("day")
    TanreiSegment("हफ़्ता").tag("week")
    TanreiSegment("महीना").tag("month")
}

// .labelStyle(.iconOnly) ही labelHidden है: शीर्षक फिर भी सेगमेंट को नाम देता है।
TanreiSegmentedButton("टेक्स्ट अलाइनमेंट", selection: $alignment) {
    TanreiSegment("बाएँ अलाइन करें", icon: "format_align_left").tag("start").labelStyle(.iconOnly)
    TanreiSegment("बीच में", icon: "format_align_center").tag("center").labelStyle(.iconOnly)
    TanreiSegment("दाएँ अलाइन करें", icon: "format_align_right").tag("end").labelStyle(.iconOnly)
}
import io.github.chnotchy.tanrei.components.TanreiSegment
import io.github.chnotchy.tanrei.components.TanreiSegmentedButton
import io.github.chnotchy.tanrei.components.TanreiSegmentedButtonSelectionMode
import io.github.chnotchy.tanrei.primitives.TanreiText
import io.github.chnotchy.tanrei.tokens.TanreiSegmentedButtonSize

// दोनों तरह के चयन के लिए एक ही कॉलबैक। एकल चयन वाला सेट एक सदस्य वाला सेट देता है।
TanreiSegmentedButton(
    onSelectionChange = { range = it.single() },
    contentDescription = "अवधि",
    selectedValue = range,
) {
    TanreiSegment(value = "day", label = "दिन")
    TanreiSegment(value = "week", label = "हफ़्ता")
    TanreiSegment(value = "month", label = "महीना")
}

TanreiSegmentedButton(
    onSelectionChange = { days = it },
    contentDescription = "दिन",
    selectionMode = TanreiSegmentedButtonSelectionMode.Multiple,
    selectedValues = days,
    size = TanreiSegmentedButtonSize.Small,
) {
    TanreiSegment(value = "mon", label = "सोम")
    TanreiSegment(value = "tue", label = "मंगल")
    // Compose उलटा फ़्लैग इस्तेमाल करता है।
    TanreiSegment(value = "wed", label = "बुध", enabled = false)
}

// labelHidden सिर्फ़ आइकन बनाता है। लेबल फिर भी सेगमेंट को नाम देता है।
TanreiSegment(value = "start", label = "बाएँ अलाइन करें", labelHidden = true, icon = { TanreiText("format_align_left") })
import 'package:tanrei/tanrei.dart';

// SegmentedButton जैसा रूप: एक Set चयन रखता है, जिसमें single रहते हुए ज़्यादा से ज़्यादा एक सदस्य होता है।
TanreiSegmentedButton<String>(
  semanticLabel: 'अवधि',
  selected: <String>{range},
  onSelectionChanged: (Set<String> value) => setState(() => range = value.single),
  segments: const <TanreiSegment<String>>[
    TanreiSegment<String>(value: 'day', label: 'दिन'),
    TanreiSegment<String>(value: 'week', label: 'हफ़्ता'),
    TanreiSegment<String>(value: 'month', label: 'महीना'),
  ],
);

TanreiSegmentedButton<String>(
  semanticLabel: 'दिन',
  multiSelectionEnabled: true,
  size: TanreiSegmentedButtonSize.small,
  selected: days,
  onSelectionChanged: (Set<String> value) => setState(() => days = value),
  segments: const <TanreiSegment<String>>[
    TanreiSegment<String>(value: 'mon', label: 'सोम'),
    TanreiSegment<String>(value: 'tue', label: 'मंगल'),
    TanreiSegment<String>(value: 'wed', label: 'बुध', enabled: false),
  ],
);

// labelHidden सिर्फ़ आइकन बनाता है। लेबल फिर भी सेगमेंट को नाम देता है।
const TanreiSegment<String>(value: 'start', label: 'बाएँ अलाइन करें', icon: Icon(AppSymbols.formatAlignLeft), labelHidden: true);
import { SegmentedButton } from '@tanrei/react-native';

// कंट्रोल्ड: onSelectionChange को मान (single) या कई मान (multiple) मिलते हैं।
<SegmentedButton
  accessibilityLabel="अवधि"
  value={range}
  onSelectionChange={setRange}
  items={[
    { value: 'day', label: 'दिन' },
    { value: 'week', label: 'हफ़्ता' },
    { value: 'month', label: 'महीना' },
  ]}
/>

<SegmentedButton
  selectionMode="multiple"
  accessibilityLabel="दिन"
  size="small"
  values={days}
  onSelectionChange={setDays}
  items={[
    { value: 'mon', label: 'सोम' },
    { value: 'tue', label: 'मंगल' },
    { value: 'wed', label: 'बुध', disabled: true },
  ]}
/>

// सिर्फ़ आइकन वाला सेगमेंट: { value: 'start', label: 'बाएँ अलाइन करें', icon: 'format_align_left', labelHidden: true }

स्पेक

साइज़ और अक्षम सेगमेंट

m3-like के साथ

संरचना

भाग विवरण
1 set The row that holds the segments: its fill, its outline and its outer corners. It gives the segments equal widths, draws the dividers between them and moves keyboard focus among them.
2 container One segment: the area that carries hover, focus and press, its selected fill, and its hit area.
3 check · वैकल्पिक The check a selected segment shows before its label, in place of its icon when it has one: the glyph check of the system's icon set, drawn with the icon set's family, fill, weight and optical size. The segmented button draws no mark of its own. Not drawn in an icon-only segment, nor where the system's check size is 0.
4 icon · वैकल्पिक A glyph before the label, or alone in an icon-only segment.
5 label The segment's text and its accessible name. It may be hidden for an icon-only segment (labelHidden) and still name it.
6 divider The line between two neighbouring segments.
7 outline The border around the whole set, drawn inside its edge.
8 focus-ring Gap-then-ring indicator shown for keyboard focus, drawn inside the focused segment.

प्रॉपर्टी

प्रॉपर्टी टाइप डिफ़ॉल्ट विवरण
selection single | multiple "single" single lets people choose one option at a time, as a radio group does; multiple lets them switch each option on and off.
value string null The value of the selected segment while selection is single; null selects none. The segmented button sets it when a segment is activated and emits change; the product may also set it.
values strings The values of the selected segments while selection is multiple: a list of strings (the platforms take a set). An empty list selects none.
size small | medium | large "medium" Visual height (32 / 36 / 40), matching Button's heights so that the set can share a row with buttons. The hit area always meets the minimum target. A design system may add values.
label string "" The accessible name of the set: the question its options answer ("Range", "Text alignment"). Required.

इवेंट

इवेंट विवरण
change The user changed the selection; carries value (single) or values (multiple) after the change, which the set now holds.

आइटम

वे आइटम के प्रकार जिन्हें कंपोनेंट दोहराता है। फ़िक्स्चर अपने आइटम क्रम से सूचीबद्ध करता है; हर प्लैटफ़ॉर्म हर प्रकार को अपने तरीक़े से नाम देता है।

segment

One option of the set: a label, an optional icon, and the value that selects it.

प्रॉपर्टी टाइप डिफ़ॉल्ट विवरण
value string "" Identifies the segment: the set's value or values name it by this, and change carries it. Unique within the set; required.
label string "" The segment's text and its accessible name. Required, even when labelHidden is true.
icon string "" The name of an icon (a glyph of the system's icon set). Give every segment of a set an icon, or none.
labelHidden boolean false Draws the icon alone and keeps label as the accessible name (an icon-only segment).
disabled boolean false Prevents choosing or clearing the segment; the arrow keys skip it.
स्पेक Web SwiftUI Jetpack Compose Flutter React Native
आइटम tanrei-segment TanreiSegment TanreiSegment TanreiSegment Segment
value · प्रॉपर्टी value tag value value value
label · प्रॉपर्टी label title label label label
icon · प्रॉपर्टी icon icon icon icon icon
labelHidden · प्रॉपर्टी labelHidden labelStyle labelHidden labelHidden labelHidden
disabled · प्रॉपर्टी disabled disabled enabled enabled disabled
टिप्पणियाँ A child element: <tanrei-segment value="week" label="Week" icon="…">, with label-hidden and disabled attributes, as <option> in a <select>. TanreiSegment(_ title:, icon:).tag(value) in the view builder, as a Picker's tagged options; .labelStyle(.iconOnly) is labelHidden; disabled follows .disabled(_:). TanreiSegment(value, label, icon, labelHidden, enabled) called in the TanreiSegmentedButton { } content lambda. enabled is the inverse flag. TanreiSegment<T>(value:, label:, icon:, labelHidden:, enabled:) in the segments: list. enabled is the inverse flag. The element type of the set's items array: { value, label, icon?, labelHidden?, disabled? }, where icon is the glyph's name.

स्टेट

व्यवहार

EARS रूप में लिखी गई आवश्यकताएँ। हर प्लैटफ़ॉर्म के इम्प्लीमेंटेशन को इन ID के आधार पर टेस्ट किया जाता है। आवश्यकताओं का पाठ स्पेक फ़ाइल से ज्यों का त्यों, अंग्रेज़ी में दिखाया गया है।

ID आवश्यकता
SEG-1 WHEN the user activates an enabled segment by pointer, touch, Enter or Space WHILE selection is single and value is not that segment's value THE segmented button SHALL set value to the segment's value, so that the segment that was selected becomes unselected, and emit change exactly once with it; WHEN the segment is already selected THE segmented button SHALL change nothing and emit nothing, because a single choice is never cleared by its own segment.
SEG-2 WHEN the user activates an enabled segment by pointer, touch, Enter or Space WHILE selection is multiple THE segmented button SHALL add the segment's value to values, or remove it when values holds it, and emit change exactly once with the new values; values may become empty.
SEG-3 WHILE a segment's disabled is true THE segmented button SHALL NOT select or clear it or emit change for it, SHALL skip it with the arrow keys, SHALL NOT make it the Tab stop and SHALL expose the disabled state to assistive technology.
SEG-4 WHILE a segment is hovered, keyboard-focused or pressed THE segmented button SHALL render its container, label, icon, check, elevation and opacity from the component tokens of its condition (selected or unselected) in the highest-precedence active state, with precedence pressed over focused over hovered; focus gained by pointer or touch SHALL NOT select the focused state. A part the interaction states recolor changes over the component's state motion; only a change of condition uses the selection motion (SEG-16).
SEG-5 WHEN a segment receives keyboard focus THE segmented button SHALL show the focus ring inside the segment's container, where the set's outline and the neighbouring segments cannot cover or clip it, without animation; focus gained by pointer or touch SHALL NOT show it.
SEG-6 WHERE the set is shorter than the minimum target THE segmented button SHALL extend each segment's hit area above and below the set to sys.target.touch for touch input and sys.target.pointer for fine pointers without changing its visual size, and SHALL make each segment at least as wide as that target, because neighbouring segments cannot extend a hit area over each other; a platform that cannot tell the input type SHALL use sys.target.touch.
SEG-7 WHILE a segment's disabled is true THE segmented button SHALL render its container, label, icon, check, elevation and opacity from the disabled component tokens of its condition; the set's outline and the dividers SHALL keep their colors, so that the set keeps a visible boundary.
SEG-8 WHEN size names a value that the active design system does not have THE segmented button SHALL render with the default value's tokens, and in debug builds report the unknown value.
SEG-9 WHEN the segment is pressed by pointer, touch, Enter or Space THE segment SHALL show the pressed state without delay and SHALL keep it visible for at least sys.motion.duration.press-hold, even when the press ends sooner.
SEG-10 WHILE pressed THE segment SHALL answer as sys.behavior.pressed-feedback names: overlay applies the pressed tokens to the whole container at once; ripple grows the pressed state layer from the point of contact (from the center for keyboard activation); dim applies the pressed opacity to the whole control and draws no state layer; none draws no answer to the press. Under ripple and dim only the container color stays with the state under the press; label, icon, check, elevation, opacity and shape still come from the pressed tokens. Under none every part stays with the state under the press. The ripple grows over comp.segmented-button.motion.feedback-duration with comp.segmented-button.motion.state-easing, fades over the state duration of its size (comp.segmented-button.motion.state-duration.small, .medium or .large) with comp.segmented-button.motion.state-easing once the press has ended and press-hold has passed, and appears whole where motion is reduced.
SEG-11 THE segment SHALL ease its container corners by sys.shape.corner-smoothing (0 is a quarter circle, 0.6 the iOS continuous corner; a platform with only the OS curve draws it for any amount above 0) and show its keyboard focus as sys.behavior.focus-style names (ring or glow); a platform that cannot draw a choice SHALL fall back to the first value and state that in its README.
SEG-12 THE segmented button SHALL render a segment from the selected condition (comp.segmented-button.selected.container.color and the other selected parts) WHILE selection is single and value equals the segment's value, or selection is multiple and values holds it, and every other segment from the unselected condition (comp.segmented-button.unselected.container.color and so on); WHEN value or values names no segment THE segmented button SHALL select nothing for that name, and WHEN a segment's value is empty or repeats another segment's THE segmented button SHALL still render it and treat the first segment with a value as the one that value selects; in debug builds it SHALL report each of these.
SEG-13 THE segmented button SHALL lay its segments out in one row, in order, in a set at least the container height of its size tall (comp.segmented-button.container.height.medium for medium, and so on), filled with comp.segmented-button.set.color, with outer corners of comp.segmented-button.set.shape, an outline of comp.segmented-button.outline.width in comp.segmented-button.outline.color inside its edge, and its segments inset from that edge by comp.segmented-button.set.padding; the outer corners of the first and last segment SHALL be the set's corners less set.padding, so that the two curves stay concentric, and every other corner of a segment SHALL be comp.segmented-button.container.shape; each segment SHALL clip its fill, state layer and ripple to its own shape, and the set SHALL NOT clip a segment's elevation.
SEG-14 THE segmented button SHALL give every segment the same width: the widest segment's content plus the padding of its size on each side (comp.segmented-button.container.padding-inline.medium for medium, and so on), a segment's content being its leading glyph (its icon, or the check where one would be drawn), the gap of its size (comp.segmented-button.container.gap.medium, and so on) and its label, measured as if the segment were selected, so that selecting a segment never changes a width; WHERE the layout gives the set more width THE segmented button SHALL divide it equally among the segments, and WHERE less, it SHALL divide what it has equally and let labels wrap onto more lines rather than truncate, growing every segment to the tallest, with at least the padding-block of its size (comp.segmented-button.container.padding-block.medium, and so on) above and below.
SEG-15 THE segmented button SHALL centre a segment's content in it, the leading glyph first; SHALL set the label in the label style of its size (comp.segmented-button.label.typescale.medium, and so on) and the label color of its condition and state; and SHALL draw the icon in the icon color of its condition and state at the icon size of its size (comp.segmented-button.icon.size.medium, and so on) through the icon helper, with the family and fill of the segment's condition (selected for a selected segment, otherwise unselected), sys.icon.weight and an optical size clamped between sys.icon.optical-size.min and sys.icon.optical-size.max.
SEG-16 WHILE a segment is selected and its label is drawn THE segmented button SHALL draw the glyph check of the system's icon set in the leading position, in place of the segment's icon when it has one, as the filter chip draws its check (CHP-13, CHP-14), at the check size of its size (comp.segmented-button.check.size.medium, and so on) in the icon color of the selected condition, with sys.icon.family.selected, sys.icon.fill.selected, the weight comp.segmented-button.check.weight (not sys.icon.weight: the check is a control's own mark drawn on the selected fill, as the checkbox's is, CHK-12) and an optical size clamped between sys.icon.optical-size.min and sys.icon.optical-size.max, and SHALL NOT mirror it when the layout direction is right-to-left; the weight SHALL change the stroke of the glyph only, the check's box staying its check size; THE segmented button SHALL draw no mark of its own (no path, shape or character of its own for the check). An icon-only segment SHALL keep its icon when selected and draw no check; WHILE the check size of the segment's size is 0 THE segmented button SHALL draw no check, reserve no room for it, and keep the icon. WHEN a segment becomes selected or unselected THE segmented button SHALL fade the check in or out (a glyph is not drawn along a path), cross-fading it with the icon where the segment has one, and change the segment's colors and elevation over comp.segmented-button.motion.selection-duration with comp.segmented-button.motion.selection-easing, re-centring the content as the check comes and goes, and SHALL show the new condition at once where motion is reduced.
SEG-17 THE segmented button SHALL draw a line of comp.segmented-button.divider.width in comp.segmented-button.divider.color between each two neighbouring segments, taking that width between them and running from the set's top padding to its bottom padding; the line SHALL keep its color and full opacity whatever the state or condition of either segment, and SHALL be hidden from assistive technology.
SEG-18 WHILE selection is single THE segmented button SHALL be one Tab stop — the selected segment, or the first enabled segment while none is selected; WHILE a segment has keyboard focus Right Arrow and Down Arrow SHALL move focus to the next enabled segment and Left Arrow and Up Arrow to the previous one, wrapping at the ends, and Home and End to the first and last enabled segment, and each move SHALL also select the segment it reaches and emit change, as a radio group does; in a right-to-left layout Left Arrow SHALL move to the next segment and Right Arrow to the previous.
SEG-19 WHILE selection is multiple THE segmented button SHALL be one Tab stop — the segment that had focus last, or else the first selected segment, or else the first enabled segment; WHILE a segment has keyboard focus Right Arrow and Down Arrow SHALL move focus to the next enabled segment and Left Arrow and Up Arrow to the previous one, wrapping at the ends, and Home and End to the first and last enabled segment, without changing the selection, and Space or Enter SHALL switch the focused segment (SEG-2); in a right-to-left layout Left Arrow SHALL move to the next segment and Right Arrow to the previous.
SEG-20 WHILE selection is single THE segmented button SHALL expose the set as a radio group named by label and each segment as a radio with its checked state; WHILE selection is multiple THE segmented button SHALL expose the set as a group named by label and each segment as a toggle button with its pressed state, as a toggle Button is; in both, each segment SHALL be named by its own label whether or not it is drawn, over a name the product gives the segment on the element (aria-label or aria-labelledby) and expose its position and the number of segments, and the icons, the check, the dividers and the outline SHALL be hidden.
SEG-21 WHEN the layout direction is right-to-left THE segmented button SHALL order the segments from the right, mirror each segment's content (the glyph to the right of the label) and apply its paddings by logical start and end, and SHALL grow a ripple from the point of contact as in left-to-right.
SEG-22 WHILE a segment's label is empty and the product gives the segment a name of its own on the element — aria-label, or aria-labelledby naming an element — THE segmented button SHALL expose that name as the segment's accessible name; WHILE a segment's label is empty and the product gives it none THE segmented button SHALL still render the segment, and in debug builds report that it has no accessible name; WHILE a segment's labelHidden is true and its icon is empty THE segmented button SHALL draw the label anyway and in debug builds report the segment; WHILE the set's label is empty, or the set holds fewer than two or more than five segments, THE segmented button SHALL still render and in debug builds report it.
SEG-23 WHEN the colors or the elevation of a segment change between interaction states THE segmented button SHALL animate them over the state duration of its size (comp.segmented-button.motion.state-duration.small, .medium or .large) with comp.segmented-button.motion.state-easing, and SHALL change them at once where motion is reduced.
SEG-24 WHILE a segment is selected THE segmented button SHALL cast the elevation of its condition and state (comp.segmented-button.selected.container.elevation at rest, and so on) outside the segment and above its neighbours; THE segmented button SHALL NOT position itself or draw anything outside the set but that elevation.
SEG-25 IF the icon set cannot draw the check yet (its font is still loading or failed to load) THE segmented button SHALL draw nothing in the check's place, never the glyph's name as text, SHALL keep the room SEG-14 measures for it so that no width changes, SHALL still expose the segment's selected state, and SHALL show the check once the icon set can draw it, without the selection motion of SEG-16.
SEG-26 THE segmented button SHALL take its layout direction from where it is used — the direction of the nearest ancestor that sets one, and the platform's own where none does — and SHALL have no direction setting of its own; WHEN that direction changes while the segmented button is shown THE segmented button SHALL draw itself for the new direction at once, without a motion of its own, keeping its selection and its focus.
SEG-27 WHERE the layout direction is right-to-left THE segmented button SHALL draw a segment's icon mirrored left to right exactly when the system's icon set marks that glyph's name as mirrored or the product forces mirroring for that use, and unmirrored when the product forbids it: the icon helper mirrors the glyph inside its own box, about the box's vertical centre line, changing neither its place, size, color and fill nor the order SEG-21 gives. THE segmented button SHALL NOT mirror a glyph itself, and SHALL NOT mirror content the product gives as an image or a view of its own rather than by a glyph's name. The check of a selected segment is never mirrored (SEG-16).
SEG-28 THE segmented button SHALL lay out a segment's label as text of its own direction, isolated from the text around it: each takes the base direction of its first strong character, or the layout direction where it has none, so that a left-to-right word, a number with its sign or unit, a telephone number and an address keep their own order in a right-to-left layout and reorder nothing beside them; THE segmented button SHALL still place each label and align its lines by the layout direction, not by the text's own.
SEG-29 WHERE the platform has ARIA attributes (the web), WHEN the product sets an aria- attribute on a segment's host, by the attribute or by the ARIA property that reflects it, THE segmented button SHALL move it to the data-aria- attribute of the same name, so that the host is no second node with its name, description or state, and SHALL expose it on the element that carries the segment's role — an id reference by the elements it names in the host's tree or a tree around it, an error message as part of the description while the segment is invalid — except those a segment owns (aria-checked, aria-pressed, aria-disabled), which it SHALL move and not expose. WHEN the product removes the aria- attribute or its data-aria- twin, or sets the ARIA property that reflects it (ariaLabel, ariaDescribedByElements…) to null, THE segmented button SHALL take it off that element. WHEN the product sets an aria- attribute a segment owns THE segmented button SHALL report it in debug builds. The set's host carries its radio group or group role itself (SEG-20), so what the product writes on it is not moved, but for a name: WHILE the set's label is not empty THE segmented button SHALL hold the product's aria-label and aria-labelledby on that host as their data-aria- twins, so that label is the set's whole name although the platform gives aria-labelledby the precedence, and WHEN label is emptied SHALL give them back as they were written; WHILE it is empty a name the product gives so is the set's name and SHALL NOT be reported as having none in debug builds (SEG-22); WHEN the product removes one, or its data-aria- twin, or sets the ARIA property that reflects it to null, THE segmented button SHALL take it away.

प्लैटफ़ॉर्म के अनुसार नामों का मिलान

पैरिटी का मतलब एक जैसे API नहीं है। हर प्लैटफ़ॉर्म एक ही कॉन्ट्रैक्ट को अपने तरीक़े से व्यक्त करता है।

स्पेक Web SwiftUI Jetpack Compose Flutter React Native
कंपोनेंट tanrei-segmented-button TanreiSegmentedButton TanreiSegmentedButton TanreiSegmentedButton SegmentedButton
selection · प्रॉपर्टी selection selection selectionMode multiSelectionEnabled selectionMode
value · प्रॉपर्टी value selection selectedValue selected value
values · प्रॉपर्टी values selection selectedValues selected values
size · प्रॉपर्टी size size size size size
label · प्रॉपर्टी label label contentDescription semanticLabel accessibilityLabel
change · इवेंट change selection onSelectionChange onSelectionChanged onSelectionChange
टिप्पणियाँ tanrei-segmented-button (selection, value, values, size, label) holds tanrei-segment children. value is an attribute and a property; values is a property (an array); the values attribute is also read, as JSON or as space-separated words, because the fixture harness writes attributes. It sets its own value or values before firing change, as a native control does. It puts role radiogroup (single) or group (multiple) and aria-label on its own element, and on each segment's inner <button> role radio with aria-checked, aria-posinset and aria-setsize (single), or aria-pressed (multiple), with a roving tabindex. A toggle button may not carry aria-posinset, so in a multiple set the row is a role="list" and each segment a role="listitem" that carries the position; ElementInternals is not used for the roles, because axe cannot see it. It is not form-associated. The check is the icon helper's check glyph in the check part (SEG-16). TanreiSegmentedButton(_ label:, selection: Binding<V?>, size:) { TanreiSegment … } for single selection and TanreiSegmentedButton(_ label:, selection: Binding<Set<V>>, size:) { … } for multiple: the binding's type is selection, and writing it is change. SwiftUI's Picker with .pickerStyle(.segmented) is not used: its segments cannot be tokenised. A single-choice segment is a button with the .isSelected trait and its position as its accessibility value; a multiple-choice segment adds the .isToggle trait (iOS 17). Lagging behind SEG-16 and SEG-25: without an installed icon font it strokes the check as a vector of its own (TanreiChipGlyph, on the checkbox's mark geometry) instead of drawing nothing. Lagging behind SEG-16's weight (the check drawn at comp.segmented-button.check.weight): its check is drawn at sys.icon.weight. One composable for both selections (Material's SingleChoiceSegmentedButtonRow and MultiChoiceSegmentedButtonRow in one): TanreiSegmentedButton(selectionMode, selectedValue, selectedValues, onSelectionChange, size, contentDescription) { TanreiSegment(…) }. State hoisting: the caller keeps selectedValue or selectedValues and moves it from onSelectionChange. The row is a selectableGroup(); a single-choice segment is selectable(role = Role.RadioButton) and a multiple-choice one toggleable(role = Role.Button), as the filter chip is. Compose has no radio group role. onSelectionChange is (Set<String>) -> Unit for both selections: a single choice passes a set of one (as the list does). Lagging behind SEG-16 and SEG-25: without an installed icon font it strokes the check as a vector of its own (TanreiDrawnGlyph, tanreiCheckPath) instead of drawing nothing. Lagging behind SEG-16's weight (the check drawn at comp.segmented-button.check.weight): its check is drawn at sys.icon.weight. Shaped like Flutter's SegmentedButton<T> but built with the widgets library, without Material: TanreiSegmentedButton<T>(segments:, selected: Set<T>, onSelectionChanged:, multiSelectionEnabled:, size:, semanticLabel:). selected holds zero or one value while multiSelectionEnabled is false; the caller moves it from onSelectionChanged. A single-choice segment is Semantics(inMutuallyExclusiveGroup: true, checked:) and a multiple-choice one Semantics(button: true, toggled:), inside a Semantics(container: true, label:) for the set. A single-choice set is exposed with SemanticsRole.radioGroup, named by semanticLabel (SEG-20). Lagging behind SEG-25: it writes the check as the Material Symbols code point U+E5CA (tanreiCheckGlyph), and without the icon font it draws whatever the fallback face has for that code point instead of nothing. Lagging behind SEG-16's weight (the check drawn at comp.segmented-button.check.weight): its check is drawn at sys.icon.weight. <SegmentedButton items={Segment[]} selectionMode value | values onSelectionChange size accessibilityLabel>; controlled, the caller moves value or values from onSelectionChange. The set has the radiogroup role (single) or the group role (multiple); each segment the radio role with accessibilityState.checked, or the button role with accessibilityState.selected, as a toggle Button is. The arrow keys work where a hardware keyboard is attached. Lagging behind SEG-25: it writes the ligature check into the glyph box, and without the icon font it prints the word instead of drawing nothing. Lagging behind SEG-16's weight (the check drawn at comp.segmented-button.check.weight): its check is drawn at sys.icon.weight.

टोकन

टोकन किसका एलियास रिज़ॉल्व किया गया मान (लाइट)
--tanrei-comp-segmented-button-check-size-large sys.icon.extra-small 16px
--tanrei-comp-segmented-button-check-size-medium sys.icon.extra-small 16px
--tanrei-comp-segmented-button-check-size-small sys.icon.extra-small 16px
--tanrei-comp-segmented-button-check-weight sys.icon.mark.weight 500
--tanrei-comp-segmented-button-container-gap-large sys.space.space100 8px
--tanrei-comp-segmented-button-container-gap-medium sys.space.space100 8px
--tanrei-comp-segmented-button-container-gap-small sys.space.space100 8px
--tanrei-comp-segmented-button-container-height-large — 40px
--tanrei-comp-segmented-button-container-height-medium — 36px
--tanrei-comp-segmented-button-container-height-small — 32px
--tanrei-comp-segmented-button-container-padding-block-large — 6px
--tanrei-comp-segmented-button-container-padding-block-medium — 6px
--tanrei-comp-segmented-button-container-padding-block-small — 6px
--tanrei-comp-segmented-button-container-padding-inline-large sys.space.space200 16px
--tanrei-comp-segmented-button-container-padding-inline-medium sys.space.space175 14px
--tanrei-comp-segmented-button-container-padding-inline-small sys.space.space150 12px
--tanrei-comp-segmented-button-container-shape sys.shape.corner.none 0px
--tanrei-comp-segmented-button-disabled-container-shape — 0px
--tanrei-comp-segmented-button-disabled-opacity — 1
--tanrei-comp-segmented-button-divider-color sys.color.outline #848484
--tanrei-comp-segmented-button-divider-width sys.border.hairline 1px
--tanrei-comp-segmented-button-focused-container-shape — 0px
--tanrei-comp-segmented-button-focused-opacity — 1
--tanrei-comp-segmented-button-hovered-container-shape — 0px
--tanrei-comp-segmented-button-hovered-opacity — 1
--tanrei-comp-segmented-button-icon-size-large sys.icon.extra-small 16px
--tanrei-comp-segmented-button-icon-size-medium sys.icon.extra-small 16px
--tanrei-comp-segmented-button-icon-size-small sys.icon.extra-small 16px
--tanrei-comp-segmented-button-motion-feedback-duration sys.motion.role.feedback 450ms
--tanrei-comp-segmented-button-motion-selection-duration sys.motion.role.selection.mark 250ms
--tanrei-comp-segmented-button-motion-selection-easing sys.motion.easing.state cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-segmented-button-motion-state-duration-large sys.motion.role.state.large 250ms
--tanrei-comp-segmented-button-motion-state-duration-medium sys.motion.role.state.default 250ms
--tanrei-comp-segmented-button-motion-state-duration-small sys.motion.role.state.compact 200ms
--tanrei-comp-segmented-button-motion-state-easing sys.motion.easing.state cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-segmented-button-outline-color sys.color.outline #848484
--tanrei-comp-segmented-button-outline-width sys.border.hairline 1px
--tanrei-comp-segmented-button-pressed-container-shape — 0px
--tanrei-comp-segmented-button-pressed-opacity — 1
--tanrei-comp-segmented-button-selected-container-color sys.color.secondary-container #eeeeee
--tanrei-comp-segmented-button-selected-container-elevation sys.elevation.level0
--tanrei-comp-segmented-button-selected-disabled-container-color — #1b1b1b · 12%
--tanrei-comp-segmented-button-selected-disabled-container-elevation —
--tanrei-comp-segmented-button-selected-disabled-icon-color — #1b1b1b · 38%
--tanrei-comp-segmented-button-selected-disabled-label-color — #1b1b1b · 38%
--tanrei-comp-segmented-button-selected-disabled-state-layer-color — #1b1b1b · 38%
--tanrei-comp-segmented-button-selected-focused-container-color — #dadada
--tanrei-comp-segmented-button-selected-focused-container-elevation —
--tanrei-comp-segmented-button-selected-focused-icon-color — #262626
--tanrei-comp-segmented-button-selected-focused-label-color — #262626
--tanrei-comp-segmented-button-selected-focused-state-layer-color — #262626
--tanrei-comp-segmented-button-selected-hovered-container-color — #dedede
--tanrei-comp-segmented-button-selected-hovered-container-elevation —
--tanrei-comp-segmented-button-selected-hovered-icon-color — #262626
--tanrei-comp-segmented-button-selected-hovered-label-color — #262626
--tanrei-comp-segmented-button-selected-hovered-state-layer-color — #262626
--tanrei-comp-segmented-button-selected-icon-color sys.color.on-secondary-container #262626
--tanrei-comp-segmented-button-selected-label-color sys.color.on-secondary-container #262626
--tanrei-comp-segmented-button-selected-pressed-container-color — #dadada
--tanrei-comp-segmented-button-selected-pressed-container-elevation —
--tanrei-comp-segmented-button-selected-pressed-icon-color — #262626
--tanrei-comp-segmented-button-selected-pressed-label-color — #262626
--tanrei-comp-segmented-button-selected-pressed-state-layer-color — #262626
--tanrei-comp-segmented-button-selected-state-layer-color comp.segmented-button.selected.label.color #262626
--tanrei-comp-segmented-button-set-color — #000000 · 0%
--tanrei-comp-segmented-button-set-padding sys.space.space0 0px
--tanrei-comp-segmented-button-set-shape sys.shape.corner.small 6px
--tanrei-comp-segmented-button-unselected-container-color — #000000 · 0%
--tanrei-comp-segmented-button-unselected-container-elevation sys.elevation.level0
--tanrei-comp-segmented-button-unselected-disabled-container-color — #000000 · 0%
--tanrei-comp-segmented-button-unselected-disabled-container-elevation —
--tanrei-comp-segmented-button-unselected-disabled-icon-color — #1b1b1b · 38%
--tanrei-comp-segmented-button-unselected-disabled-label-color — #1b1b1b · 38%
--tanrei-comp-segmented-button-unselected-disabled-state-layer-color — #1b1b1b · 38%
--tanrei-comp-segmented-button-unselected-focused-container-color — #1b1b1b · 10%
--tanrei-comp-segmented-button-unselected-focused-container-elevation —
--tanrei-comp-segmented-button-unselected-focused-icon-color — #4b4b4b
--tanrei-comp-segmented-button-unselected-focused-label-color — #1b1b1b
--tanrei-comp-segmented-button-unselected-focused-state-layer-color — #1b1b1b
--tanrei-comp-segmented-button-unselected-hovered-container-color — #1b1b1b · 8%
--tanrei-comp-segmented-button-unselected-hovered-container-elevation —
--tanrei-comp-segmented-button-unselected-hovered-icon-color — #4b4b4b
--tanrei-comp-segmented-button-unselected-hovered-label-color — #1b1b1b
--tanrei-comp-segmented-button-unselected-hovered-state-layer-color — #1b1b1b
--tanrei-comp-segmented-button-unselected-icon-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-segmented-button-unselected-label-color sys.color.on-surface #1b1b1b
--tanrei-comp-segmented-button-unselected-pressed-container-color — #1b1b1b · 10%
--tanrei-comp-segmented-button-unselected-pressed-container-elevation —
--tanrei-comp-segmented-button-unselected-pressed-icon-color — #4b4b4b
--tanrei-comp-segmented-button-unselected-pressed-label-color — #1b1b1b
--tanrei-comp-segmented-button-unselected-pressed-state-layer-color — #1b1b1b
--tanrei-comp-segmented-button-unselected-state-layer-color comp.segmented-button.unselected.label.color #1b1b1b
--tanrei-comp-segmented-button-label-typescale-large sys.typescale.label 500 14px/1.4286
--tanrei-comp-segmented-button-label-typescale-medium sys.typescale.label 500 14px/1.4286
--tanrei-comp-segmented-button-label-typescale-small sys.typescale.label 500 14px/1.4286

फ़िक्स्चर

मानक रेंडरिंग। हर प्लैटफ़ॉर्म हर फ़िक्स्चर का स्नैपशॉट एक ही ID से लेता है, ताकि नतीजों की तुलना की जा सके।

इससे जनरेट किया गया: specs/segmented-button.spec.json, tokens/comp/segmented-button.tokens.json, design/tokens/

दिशानिर्देश

कब इस्तेमाल करें

सेगमेंटेड बटन तब इस्तेमाल करें जब किसी एक छोटे सवाल के कुछ तय जवाब हों और वे सब लोगों को एक साथ दिखने चाहिए: चार्ट की अवधि, लिस्ट का लेआउट, पैराग्राफ़ का अलाइनमेंट, वे दिन जिन पर रिमाइंडर दोहराया जाता है। असर तुरंत दिखना चाहिए, क्योंकि एकल चयन में ऐरो कुंजियाँ चलते-चलते चुनती भी हैं।

दो से पाँच विकल्प ठीक बैठते हैं। पाँच से ज़्यादा हों, तो मेन्यू या लिस्ट इस्तेमाल करें। जब चुनाव ही किसी फ़ॉर्म का मुख्य काम हो, तो रेडियो बटन ज़्यादा ठीक रहते हैं। जब जवाब से यह बदलता हो कि स्क्रीन पर कौन-सा कॉन्टेंट रहेगा, तो टैब इस्तेमाल करें।

सेगमेंटेड बटन, बटन ग्रुप, चिप या टैब

ये चारों कुछ संबंधित चीज़ों को एक पंक्ति में रखते हैं, इसलिए इनमें आसानी से भ्रम हो जाता है। फ़र्क़ इसमें है कि दबाने पर क्या होता है और कीबोर्ड इनके भीतर कैसे चलता है।

कंपोनेंट यह क्या है चयन कीबोर्ड किसके लिए इस्तेमाल करें
सेगमेंटेड बटन एक कंट्रोल: आपस में जुड़े दो से पाँच विकल्प, जो एक ही सवाल का जवाब देते हैं। इसका अपना, मान के आधार पर: एक विकल्प, या कई। एक Tab स्टॉप। ऐरो कुंजियाँ विकल्पों के बीच ले जाती हैं, और एकल चयन में वे चुनती भी हैं। कुछ तय जवाबों वाली सेटिंग, जो तुरंत लागू होती है: दिन, हफ़्ता, महीना; बाएँ, बीच में, दाएँ।
बटन ग्रुप अलग-अलग बटनों की एक पंक्ति या एक कॉलम, अलग-अलग दूरी पर या एक ही शेप में जुड़े हुए। कोई नहीं। ग्रुप का टॉगल बटन अपना चालू या बंद स्टेट ख़ुद रखता है। हर बटन अपना अलग Tab स्टॉप है। संबंधित क्रियाएँ: रद्द करें, ड्राफ़्ट सेव करें, प्रकाशित करें; एक-दूसरे से स्वतंत्र टॉगल के रूप में बोल्ड, इटैलिक और अंडरलाइन।
चिप एक पंक्ति में अलग-अलग छोटे कंट्रोल, जो अगली पंक्ति में जाती है या स्क्रॉल होती है। हर फ़िल्टर चिप अपने आप में चालू या बंद होती है। हर चिप अपना अलग Tab स्टॉप है। लिस्ट के ऊपर के फ़िल्टर, सुझाए गए जवाब, व्यक्ति के दर्ज किए हुए आइटम।
टैब एक ही विषय के व्यू, हर एक अपने पैनल के साथ। एक टैब: वह व्यू जो स्क्रीन पर है। एक Tab स्टॉप। ऐरो कुंजियाँ ले जाती हैं और चुनती हैं। यह बदलना कि कौन-सा कॉन्टेंट दिखे: अवलोकन, गतिविधि, सेटिंग।

एक झटपट कसौटी: अगर उसे दबाने से कुछ होता है, तो वह बटन ग्रुप है। अगर वह एक मान सेट करता है, तो वह सेगमेंटेड बटन है, या चिप जब विकल्प बहुत सारे हों या एक-दूसरे से स्वतंत्र हों। अगर वह नीचे का कॉन्टेंट बदल देता है, तो वह टैब है।

एक चुनाव या कई

  • Single (selection="single", डिफ़ॉल्ट) एक रेडियो ग्रुप है। किसी सेगमेंट को चुनने से उससे पहले वाला चुनाव हट जाता है। चुने हुए सेगमेंट को दोबारा दबाने से कुछ नहीं होता, इसलिए एकल चयन को उसके अपने सेगमेंट से हटाया नहीं जा सकता। सेट की शुरुआत कुछ भी चुने बिना हो सकती है (value ख़ाली), उस फ़ॉर्म के लिए जिसे दिखाना ही है कि अभी तक कुछ नहीं चुना गया।
  • Multiple टॉगल बटनों का एक ग्रुप है। हर सेगमेंट चालू और बंद होता है, और सेट में अंत में कोई भी चुना हुआ न रहे, यह हो सकता है। अगर आपके प्रॉडक्ट को कम से कम एक चाहिए, तो वह बदलाव लागू न करें जो सेट को ख़ाली छोड़ दे।

सेट का अपना कोई disabled नहीं है। सेगमेंट को एक-एक करके अक्षम करें। अक्षम सेगमेंट अपनी जगह और अपनी आउटलाइन बनाए रखता है, और ऐरो कुंजियाँ उसे लाँघ जाती हैं।

लेबल, आइकन और चेक

  • चयनित सेगमेंट अपने लेबल से पहले एक चेक दिखाता है, और आइकन हो तो उसकी जगह, इसलिए चयन कभी सिर्फ़ फ़िल से नहीं बताया जाता। सिर्फ़ आइकन वाला सेगमेंट अपना आइकन बनाए रखता है और उसे भरा हुआ बनाता है। कोई डिज़ाइन सिस्टम चेक का साइज़ 0 कर सकता है: तब वह कोई चेक नहीं बनाता, और चयन को फ़िल और एलिवेशन से दिखाता है।
  • हर सेगमेंट सबसे चौड़े सेगमेंट जितना चौड़ा होता है, और यह चौड़ाई ऐसे नापी जाती है मानो वह चयनित हो, इसलिए चेक के दिखने से कोई पड़ोसी कभी नहीं खिसकता। कम जगह मिलने पर लेबल कई पंक्तियों में टूट जाते हैं और हर सेगमेंट सबसे ऊँचे जितना बढ़ जाता है। वे कभी कटते नहीं।
  • labelHidden सिर्फ़ आइकन बनाता है। लेबल फिर भी ज़रूरी है, क्योंकि वह सेगमेंट का एक्सेसिबल नाम बना रहता है।
  • साइज़ सेट की ऊँचाई तय करता है। ये साइज़ हर स्टेप पर Button की ऊँचाइयाँ नहीं हैं (m3-like प्रीसेट में small और medium Button से मेल खाते हैं और large उससे कम है), इसलिए सेट को उसके बग़ल के बटनों से ऊँचाई के आधार पर मिलाएँ, साइज़ के नाम के आधार पर नहीं।

करें

  • सेट को ऐसा लेबल दें जो वह सवाल पूछे जिसका जवाब उसके विकल्प देते हैं: “अवधि”, “टेक्स्ट अलाइनमेंट”।
  • लेबल एक या दो शब्दों के रखें, और रूप में एक जैसे: दिन, हफ़्ता, महीना।
  • सेट के हर सेगमेंट को आइकन दें, या किसी को नहीं।
  • जब कोई समझदारी भरा डिफ़ॉल्ट हो तो शुरुआती मान चुनें, ताकि कंट्रोल कभी बिना जवाब का न दिखे।

न करें

  • क्रियाओं के लिए सेगमेंटेड बटन इस्तेमाल न करें। सेगमेंट एक चुनाव है, और वह कोई click एमिट नहीं करता। बटन ग्रुप इस्तेमाल करें।
  • इसे उन व्यू के बीच बदलने के लिए इस्तेमाल न करें जिनमें से हर एक स्क्रीन को भरता है। टैब इस्तेमाल करें।
  • एक सेट में पाँच से ज़्यादा सेगमेंट न रखें, और न बहुत अलग-अलग लंबाई वाले लेबल। हर सेगमेंट सबसे चौड़े सेगमेंट की चौड़ाई लेता है।
  • सेगमेंट का लेबल उसके स्टेट के साथ न बदलें। चयन अलग से पढ़कर सुनाया जाता है।

सुलभता

रोल
radiogroup
लेबलिंग
The set is named by label: the question its options answer. Each segment is named by its own label, drawn or not (labelHidden). Icons, the check, the dividers and the outline are decorative: a segment's state is announced from its checked or pressed state, never from the check.
न्यूनतम टार्गेट
दिखने वाला आकार छोटा होने पर भी हिट एरिया न्यूनतम टार्गेट साइज़ को पूरा करता है। minimum 32px · pointer 44px · spacing 8px · touch 48px

कीबोर्ड

कुंजियाँ क्रिया
Tab / Shift+Tab Moves focus into the set (to the selected segment, the last focused one, or the first enabled one) and out of it.
Right Arrow / Down Arrow Moves focus to the next enabled segment, wrapping; with single selection it also selects it (Left Arrow in right-to-left layouts).
Left Arrow / Up Arrow Moves focus to the previous enabled segment, wrapping; with single selection it also selects it (Right Arrow in right-to-left layouts).
Home / End Moves focus to the first or last enabled segment; with single selection it also selects it.
Enter / Space Selects the focused segment (single) or switches it on or off (multiple).

टिप्पणियाँ

  • Single selection is a radio group: arrow keys move and select at once, as the radio button and tabs do, because a segment shows its effect without a noticeable delay. Multiple selection is a group of toggle buttons with one Tab stop: arrow keys only move focus, and Space or Enter switches.
  • Selection is the set's: value or values holds the selected segments' values, and change carries the new ones. A segment's disabled is its own.
  • iOS has no radio role: a segment of a single-choice set is a button with the selected trait and its position ("2 of 3") in its accessibility value, as the radio button is. Compose has no radio group role; the set is a selectable group and each segment `Role.RadioButton` (single) or a toggleable `Role.Button` (multiple), as the filter chip is.
  • A segmented button chooses among options of one setting. Actions belong to a button group; switching views of one subject belongs to tabs.
  • Text size does not clip a segment: labels wrap and every segment grows to the tallest. The icon is not text and keeps its size.
  • How a state looks is a value decision of the active design system; components read the state's tokens and never compute the effect themselves.

इससे जनरेट किया गया: specs/segmented-button.spec.json, tokens/sys/measure.tokens.json

कंपोनेंट क्या सँभालता है

  • एकल चयन में सेट अपने लेबल के नाम वाला एक रेडियो ग्रुप है, और हर सेगमेंट अपने checked स्टेट वाला एक रेडियो। बहु चयन में सेट अपने लेबल के नाम वाला एक ग्रुप है, और हर सेगमेंट अपने दबाए हुए स्टेट वाला एक टॉगल बटन।
  • हर सेगमेंट का नाम उसके अपने लेबल से आता है, चाहे वह दिखता हो या नहीं, और वह अपनी जगह और सेगमेंट की संख्या बताता है। आइकन, चेक, डिवाइडर और आउटलाइन छिपे रहते हैं। स्टेट कभी चेक से पढ़कर नहीं सुनाया जाता।
  • सेट एक Tab स्टॉप है: चयनित सेगमेंट, या बहु चयन में वह जिस पर आख़िरी बार फ़ोकस था, या फिर पहला सक्षम सेगमेंट। ऐरो कुंजियाँ अगले या पिछले सक्षम सेगमेंट पर ले जाती हैं और सिरे से घूमकर दूसरे सिरे पर आ जाती हैं, और Home और End सिरों तक पहुँचाती हैं। एकल चयन में फ़ोकस जिस सेगमेंट पर जाता है, वह चुन भी लिया जाता है। बहु चयन में Space और Enter फ़ोकस वाले सेगमेंट को बदलती हैं। दाएँ से बाएँ वाले लेआउट में Left Arrow अगले सेगमेंट पर ले जाती है।
  • अक्षम सेगमेंट को ऐरो कुंजियाँ लाँघ जाती हैं, वे कभी Tab स्टॉप नहीं होते, और सहायक तकनीक को अक्षम के रूप में मिलते हैं।
  • हर सेगमेंट का हिट एरिया सेट के ऊपर और नीचे न्यूनतम टार्गेट तक पहुँचता है, और हर सेगमेंट कम से कम एक टार्गेट जितना चौड़ा है, क्योंकि पड़ोसी एक-दूसरे के ऊपर तक नहीं पहुँच सकते।
  • फ़ोकस इंडिकेटर फ़ोकस वाले सेगमेंट के भीतर बनता है, जहाँ आउटलाइन और पड़ोसी उसे ढक नहीं सकते। वह सिर्फ़ कीबोर्ड फ़ोकस के लिए दिखता है।
  • बड़े टेक्स्ट साइज़ पर लेबल अगली पंक्ति में जाते हैं और हर सेगमेंट सबसे ऊँचे जितना बढ़ जाता है। आइकन अपना साइज़ बनाए रखता है।
  • डीबग बिल्ड इन बातों की रिपोर्ट करते हैं: सेट या सेगमेंट के लेबल का न होना, बिना आइकन का छिपा हुआ लेबल, ऐसा value या values जो किसी सेगमेंट का नाम नहीं लेते, सेगमेंट का ख़ाली या दोहराया हुआ मान, और दो से कम या पाँच से ज़्यादा सेगमेंट वाला सेट।

प्लैटफ़ॉर्म की ज्ञात कमियाँ:

  • वेब पर, बहु चयन वाला सेट हर सेगमेंट को उसकी जगह सेगमेंट के इर्द-गिर्द की एक लिस्ट के ज़रिए देता है, क्योंकि टॉगल बटन अपनी कोई जगह नहीं रख सकता।
  • SwiftUI में रेडियो ग्रुप का कोई रोल नहीं है। सेट अपने लेबल के नाम वाला एक कंटेनर है। एकल चयन वाले सेट का सेगमेंट selected ट्रेट वाला एक बटन है, जिसका मान उसकी जगह है (“2 of 3”), फ़िलहाल सिर्फ़ अंग्रेज़ी में। बहु चयन वाले सेट का सेगमेंट एक टॉगल है और कोई जगह नहीं बताता, क्योंकि उसका अपना मान टॉगल के चालू या बंद की जगह ले लेता।
  • SwiftUI: सेट उतनी चौड़ाई लेता है जितनी उसे दी जाती है, जैसे SwiftUI का सेगमेंटेड पिकर लेता है। .fixedSize(horizontal: true, vertical: false) उसकी स्वाभाविक चौड़ाई बनाए रखता है। सेगमेंट की शैडो और फ़ोकस रिंग हर कोने पर उसका सबसे बड़ा कोना इस्तेमाल करते हैं। आइकन के रूप में दिया गया SF Symbol चयनित होने पर अपने भरे हुए रूप में नहीं बदलता: .fill वाला सिंबल ख़ुद दें। ऐरो कुंजियाँ नियमों के रूप में टेस्ट की गई हैं, सिम्युलेटर पर कीबोर्ड से नहीं।
  • Compose में रेडियो ग्रुप का कोई रोल नहीं है। सेट एक selectable ग्रुप है, और हर सेगमेंट एक रेडियो बटन (single) या एक toggleable बटन (multiple) है, जैसे फ़िल्टर चिप है।
  • Flutter न सेगमेंट की जगह बताता है, न सेगमेंट की संख्या, और बहु चयन वाला सेट ग्रुप की जगह अपने लेबल के नाम वाला एक कंटेनर है, क्योंकि Flutter के सिमैंटिक्स में दोनों में से कोई प्रॉपर्टी नहीं है।
  • React Native: बराबर चौड़ाइयाँ पहले लेआउट के बाद हर लेबल को नापने से आती हैं, इसलिए जिस सेट का पैरेंट पहले फ़्रेम पर उससे सँकरा हो, वह अपने सबसे चौड़े लेबल से भी सँकरी चौड़ाई ले सकता है। हार्डवेयर कीबोर्ड की ऐरो कुंजियाँ, और Android पर उठे हुए चयन की अपने पड़ोसियों के ऊपर पड़ने वाली शैडो, किसी डिवाइस पर जाँची नहीं गई हैं।
  • cupertino सिस्टम में small और medium सेट 28 और 32 की जगह 30 और 34 ऊँचे हैं, और सिरे के सेगमेंट के भीतरी कोने उनके बाहरी कोनों से ज़्यादा गोल हैं। दोनों टोकन या स्पेक के किसी फ़ैसले का इंतज़ार कर रहे हैं।

आपको क्या करना है

  • सेट को एक लेबल दें, और हर सेगमेंट को एक लेबल, सिर्फ़ आइकन वाले सेगमेंट समेत।
  • चुनाव का असर तुरंत दिखाएँ, कंट्रोल के पास। एकल चयन में कीबोर्ड इस्तेमाल करने वाला व्यक्ति फ़ोकस ले जाकर ही चुनता है, इसलिए असर धीमा हो तो ऐरो कुंजियाँ अटकी हुई-सी लगती हैं। अगर उसमें समय लगना ही है, तो प्रगति वहाँ दिखाएँ जहाँ नतीजा दिखेगा।
  • जब यह साफ़ न हो कि अक्षम सेगमेंट क्यों नहीं चुने जा सकते, तो पास में उसका कारण दें।
  • वेब पर सेगमेंटेड बटन कोई फ़ॉर्म कंट्रोल नहीं है। फ़ॉर्म के साथ उसका मान भेजने के लिए उसे change से एक hidden इनपुट में कॉपी करें।