MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Tab

Function Tab

packages/@react-spectrum/s2/src/Tabs.tsx:466–532  ·  view source on GitHub ↗
(props: TabProps)

Source from the content-addressed store, hash-verified

464});
465
466export function Tab(props: TabProps): ReactNode {
467 let {density, orientation, labelBehavior, baseId} = useContext(InternalTabsContext) ?? {};
468
469 // Derive a stable content id from the shared baseId on InternalTabsContext.
470 // Prevents infinite loop when rendering across multiple CollectionBuilder portals.
471 let fallbackId = useId();
472 let contentId = `${baseId ?? fallbackId}-content-${props.id ?? fallbackId}`;
473 let ariaLabelledBy = props['aria-labelledby'] || '';
474
475 return (
476 <RACTab
477 {...props}
478 // @ts-ignore
479 originalProps={props}
480 aria-labelledby={`${labelBehavior === 'hide' ? contentId : ''} ${ariaLabelledBy}`}
481 style={props.UNSAFE_style}
482 className={renderProps =>
483 (props.UNSAFE_className || '') +
484 tab({...renderProps, density, labelBehavior, orientation}, props.styles)
485 }>
486 {({
487 // @ts-ignore
488 isMenu,
489 isDisabled
490 }) => {
491 if (isMenu) {
492 return props.children;
493 } else {
494 return (
495 <Provider
496 values={[
497 [
498 TextContext,
499 {
500 id: contentId,
501 styles: style({
502 order: 1,
503 display: {
504 labelBehavior: {
505 hide: 'none'
506 }
507 }
508 })({labelBehavior})
509 }
510 ],
511 [
512 IconContext,
513 {
514 render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
515 styles: icon
516 }
517 ]
518 ]}>
519 <TabInner orientation={orientation!} isDisabled={isDisabled}>
520 {typeof props.children === 'string' ? (
521 <Text>{props.children}</Text>
522 ) : (
523 props.children

Callers

nothing calls this directly

Calls 3

useIdFunction · 0.90
centerBaselineFunction · 0.90
tabFunction · 0.50

Tested by

no test coverage detected