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

Function Tab

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

useIdFunction · 0.90
centerBaselineFunction · 0.90
tabFunction · 0.50

Tested by

no test coverage detected