carbon-react 158.25.2 → 158.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,4 +51,4 @@ Thanks to [Chromatic](https://www.chromatic.com/) for providing the visual testi
51
51
 
52
52
  Carbon is licensed under the [Apache-2.0 licence](LICENSE).
53
53
 
54
- Copyright (c) 2018-2025 Sage Group Plc. All rights reserved.
54
+ Copyright (c) 2018-2026 Sage Group Plc. All rights reserved.
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { TabsHandle, TabListProps, TabPanelProps, TabProps, TabsProps } from "./tabs.types";
3
- export declare const TabPanel: ({ children, id, tabId }: TabPanelProps) => React.JSX.Element;
4
- export declare const Tab: ({ controls, error, id, label, leftSlot, rightSlot, warning, info, }: TabProps) => React.JSX.Element;
3
+ export declare const TabPanel: ({ children, id, tabId, ...rest }: TabPanelProps) => React.JSX.Element;
4
+ export declare const Tab: ({ controls, error, id, label, leftSlot, rightSlot, warning, info, ...rest }: TabProps) => React.JSX.Element;
5
5
  export declare const TabList: React.ForwardRefExoticComponent<TabListProps & React.RefAttributes<TabsHandle>>;
6
- export declare const Tabs: ({ children, labelledBy, orientation, selectedTabId, size, }: TabsProps) => React.JSX.Element;
6
+ export declare const Tabs: ({ children, labelledBy, orientation, selectedTabId, size, ...rest }: TabsProps) => React.JSX.Element;
7
7
  export default Tabs;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{forwardRef as n,useState as i,useEffect as o,useRef as l,useImperativeHandle as a,useCallback as s}from"react";import{TabsProvider as c,useTabs as d}from"./tabs.context.js";import{StyledTabs as b,StyledTab as u,StyledTabListWrapper as f,StyledTabList as h,Spacer as g,StyledTabPanel as p,StyledScrollButton as m,StyledScrollButtonPlaceholder as v}from"./tabs.style.js";import y from"../../../__internal__/utils/logger/index.js";import _ from"../../../hooks/__internal__/useResizeObserver/useResizeObserver.js";import w from"../../../hooks/__internal__/useLocale/useLocale.js";import I from"../../icon/icon.component.js";import{TabProvider as k}from"./tab.context.js";import x from"../../../hooks/__internal__/usePrevious/index.js";const T=({children:t,id:r,tabId:n})=>{const{activeTab:i}=d();return e(k,{tabId:n,visible:n===i,children:e(p,{id:r,role:"tabpanel","aria-labelledby":n,children:t})})};let z=!1;const j=({controls:r,error:n=!1,id:l,label:a,leftSlot:s,rightSlot:c,warning:b=!1,info:f=!1})=>{const h=w(),[g,p]=i(n),[m,v]=i(b),[_,x]=i(f),{activeTab:T,focusIndex:j,orientation:L,setActiveTab:S,setCurrentTabId:A,setFocusIndex:O,size:C,errors:R,warnings:N,infos:B}=d(),E=T===l;o((()=>{E&&A(l)}),[l,E,A]),!s&&!c||"string"==typeof a||z||(y.warn("[WARNING] Using `leftSlot` and/or `rightSlot` is not supported when `label` is not a string. Please use `leftSlot` and/or `rightSlot` alongside a string `label`, or use the `label` prop exclusively."),z=!0),o((()=>{if(j===l){const e=document.getElementById(l);null==e||e.focus()}}),[j,l,A]),o((()=>{let e=R[l],t=N[l],r=B[l];if(n&&!e&&(e={static:n}),b&&!t&&(t={static:b}),f&&!r&&(r={static:f}),!e)return void p(!1);const i=Object.keys(e).map((t=>e[t])).filter((e=>!1!==e)),o=n||i.length>0;if(p(o),!t)return void v(!1);const a=Object.keys(t).map((e=>t[e])).filter((e=>!1!==e)),s=b||a.length>0;if(v(s),!r)return void x(!1);const c=Object.keys(r).map((e=>r[e])).filter((e=>!1!==e)),d=f||c.length>0;x(d)}),[n,l,R,N,b,B,f]);const W=()=>{if(g||m||_){if(g)return e(I,{"data-role":"icon-error",type:"error",ariaLabel:h.tabs.error(),color:"#db004e"});if(m)return e(I,{"data-role":"icon-warning",type:"warning",ariaLabel:h.tabs.warning(),color:"#d64309"});if(_)return e(I,{"data-role":"icon-info",type:"info",ariaLabel:h.tabs.info(),color:"#0060a7ff"})}return null};return e(k,{tabId:l,visible:!0,children:e(u,{activeTab:T===l,"aria-controls":r,"aria-selected":E?"true":"false",error:g,info:_,id:l,onClick:()=>{S(l),O(l)},orientation:L,role:"tab",size:C,type:"button",tabIndex:T===l?0:-1,warning:m,children:t("span","string"==typeof a?{className:"tab-title-content-wrapper",children:[s,a,c,W()]}:{className:"tab-title-content-wrapper",children:[a,W()]})})})},L=n((({ariaLabel:n,children:c,onTabChange:b},u)=>{const p=l(null),{activeTab:y,focusIndex:w,orientation:k,selectedTabId:T,setFocusIndex:z,setActiveTab:j,size:L}=d();a(u,(()=>({focusTab:e=>{var t;const r=null===(t=p.current)||void 0===t?void 0:t.querySelector(`#${e}`);null==r||r.focus(),z(e),j(e)}})));const S=s((()=>{var e;const t=(null===(e=p.current)||void 0===e?void 0:e.querySelectorAll("[role='tab']"))||[];return Array.from(t).map((e=>e.id)).filter((e=>e))}),[]);o((()=>{if(T)j(T);else if(!y){const e=S()[0];j(e)}}),[y,S,T,j]);const A=x(y);o((()=>{A&&A!==y&&(null==b||b(y))}),[y,b,A]);const[O,C]=i(!1),[R,N]=i(!1),[B,E]=i(!1),W=s((()=>{if(p.current){const e=p.current.scrollWidth-p.current.clientWidth-20;C(e>0),N(p.current.scrollLeft>=20),E(p.current.scrollLeft<=e)}}),[]);_(p,(()=>{W()})),o((()=>{p.current&&W()}),[W]);const q=e=>{p.current&&("left"===e?p.current.scrollLeft-=200:p.current.scrollLeft+=200,W())};return e(r,{children:t(f,{children:["vertical"!==k&&O?R?e(m,{"data-role":"tab-navigation-button-left",id:"tab-navigation-button-left",onClick:()=>q("left"),size:L,tabIndex:-1,title:"Scroll Tabs Left",type:"button",children:e(I,{type:"chevron_left"})}):e(v,{size:L}):null,t(h,{"aria-label":n,id:"tablist",onKeyDown:e=>{const t=S(),r=t.indexOf(w||y),n=t.length-1;if(-1===r)return;let i=r;switch(e.key){case"Home":i=0;break;case"End":i=n;break;case"ArrowRight":i=(r+1)%t.length;break;case"ArrowLeft":i=(r-1+t.length)%t.length;break;case"ArrowUp":"vertical"===k&&(i=(r-1+t.length)%t.length);break;case"ArrowDown":"vertical"===k&&(i=(r+1)%t.length);break;case"Enter":case" ":return void j(y);default:return}z(t[i])},orientation:k,ref:p,role:"tablist",size:L,tabIndex:-1,children:[c,e(g,{})]}),"vertical"!==k&&O?B?e(m,{"data-role":"tab-navigation-button-right",id:"tab-navigation-button-right",onClick:()=>q("right"),size:L,tabIndex:-1,title:"Scroll Tabs Right",type:"button",children:e(I,{type:"chevron_right"})}):e(v,{size:L}):null]})})})),S=({children:t,labelledBy:r="",orientation:n="horizontal",selectedTabId:i,size:o="medium"})=>e(c,{labelledBy:r,orientation:n,selectedTabId:i,size:o,children:e(b,{id:"tabs-container",orientation:n,children:t})});export{j as Tab,L as TabList,T as TabPanel,S as Tabs,S as default};
1
+ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{forwardRef as n,useState as o,useEffect as i,useRef as l,useImperativeHandle as a,useCallback as c}from"react";import{TabsProvider as s,useTabs as b}from"./tabs.context.js";import{StyledTabs as u,StyledTab as d,StyledTabListWrapper as f,StyledTabList as p,StyledTabPanel as h,StyledScrollButton as g,StyledScrollButtonPlaceholder as y,Spacer as m}from"./tabs.style.js";import v from"../../../__internal__/utils/logger/index.js";import O from"../../../hooks/__internal__/useResizeObserver/useResizeObserver.js";import j from"../../../hooks/__internal__/useLocale/useLocale.js";import w from"../../icon/icon.component.js";import{TabProvider as _}from"./tab.context.js";import I from"../../../hooks/__internal__/usePrevious/index.js";import k from"../../../__internal__/utils/helpers/tags/tags.js";function x(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function S(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){x(e,t,r[t])}))}return e}function T(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}function P(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}const z=t=>{var{children:r,id:n,tabId:o}=t,i=P(t,["children","id","tabId"]);const{activeTab:l}=b();return e(_,{tabId:o,visible:o===l,children:e(h,T(S({id:n,role:"tabpanel","aria-labelledby":o},k("tab-panel",i)),{children:r}))})};let L=!1;const A=r=>{var{controls:n,error:l=!1,id:a,label:c,leftSlot:s,rightSlot:u,warning:f=!1,info:p=!1}=r,h=P(r,["controls","error","id","label","leftSlot","rightSlot","warning","info"]);const g=j(),[y,m]=o(l),[O,I]=o(f),[x,z]=o(p),{activeTab:A,focusIndex:C,orientation:D,setActiveTab:E,setCurrentTabId:R,setFocusIndex:B,size:N,errors:W,warnings:q,infos:F}=b(),U=A===a;i((()=>{U&&R(a)}),[a,U,R]),!s&&!u||"string"==typeof c||L||(v.warn("[WARNING] Using `leftSlot` and/or `rightSlot` is not supported when `label` is not a string. Please use `leftSlot` and/or `rightSlot` alongside a string `label`, or use the `label` prop exclusively."),L=!0),i((()=>{if(C===a){const e=document.getElementById(a);null==e||e.focus()}}),[C,a,R]),i((()=>{let e=W[a],t=q[a],r=F[a];if(l&&!e&&(e={static:l}),f&&!t&&(t={static:f}),p&&!r&&(r={static:p}),!e)return void m(!1);const n=Object.keys(e).map((t=>e[t])).filter((e=>!1!==e)),o=l||n.length>0;if(m(o),!t)return void I(!1);const i=Object.keys(t).map((e=>t[e])).filter((e=>!1!==e)),c=f||i.length>0;if(I(c),!r)return void z(!1);const s=Object.keys(r).map((e=>r[e])).filter((e=>!1!==e)),b=p||s.length>0;z(b)}),[l,a,W,q,f,F,p]);const G=()=>{if(y||O||x){if(y)return e(w,{"data-role":"icon-error",type:"error",ariaLabel:g.tabs.error(),color:"#db004e"});if(O)return e(w,{"data-role":"icon-warning",type:"warning",ariaLabel:g.tabs.warning(),color:"#d64309"});if(x)return e(w,{"data-role":"icon-info",type:"info",ariaLabel:g.tabs.info(),color:"#0060a7ff"})}return null};return e(_,{tabId:a,visible:!0,children:e(d,T(S({activeTab:A===a,"aria-controls":n,"aria-selected":U?"true":"false",error:y,info:x,id:a,onClick:()=>{E(a),B(a)},orientation:D,role:"tab",size:N,type:"button",tabIndex:A===a?0:-1,warning:O},k("tab",h)),{children:t("span","string"==typeof c?{className:"tab-title-content-wrapper",children:[s,c,u,G()]}:{className:"tab-title-content-wrapper",children:[c,G()]})}))})},C=n(((n,s)=>{var{ariaLabel:u,children:d,onTabChange:h}=n,v=P(n,["ariaLabel","children","onTabChange"]);const j=l(null),{activeTab:_,focusIndex:x,orientation:z,selectedTabId:L,setFocusIndex:A,setActiveTab:C,size:D}=b();a(s,(()=>({focusTab:e=>{var t;const r=null===(t=j.current)||void 0===t?void 0:t.querySelector(`#${e}`);null==r||r.focus(),A(e),C(e)}})));const E=c((()=>{var e;const t=(null===(e=j.current)||void 0===e?void 0:e.querySelectorAll("[role='tab']"))||[];return Array.from(t).map((e=>e.id)).filter((e=>e))}),[]);i((()=>{if(L)C(L);else if(!_){const e=E()[0];C(e)}}),[_,E,L,C]);const R=I(_);i((()=>{R&&R!==_&&(null==h||h(_))}),[_,h,R]);const[B,N]=o(!1),[W,q]=o(!1),[F,U]=o(!1),G=c((()=>{if(j.current){const e=j.current.scrollWidth-j.current.clientWidth-20;N(e>0),q(j.current.scrollLeft>=20),U(j.current.scrollLeft<=e)}}),[]);O(j,(()=>{G()})),i((()=>{j.current&&G()}),[G]);const H=e=>{j.current&&("left"===e?j.current.scrollLeft-=200:j.current.scrollLeft+=200,G())};return e(r,{children:t(f,{children:["vertical"!==z&&B?W?e(g,{"data-role":"tab-navigation-button-left",id:"tab-navigation-button-left",onClick:()=>H("left"),size:D,tabIndex:-1,title:"Scroll Tabs Left",type:"button",children:e(w,{type:"chevron_left"})}):e(y,{size:D}):null,t(p,T(S({"aria-label":u,id:"tablist",onKeyDown:e=>{const t=E(),r=t.indexOf(x||_),n=t.length-1;if(-1===r)return;let o=r;switch(e.key){case"Home":o=0;break;case"End":o=n;break;case"ArrowRight":o=(r+1)%t.length;break;case"ArrowLeft":o=(r-1+t.length)%t.length;break;case"ArrowUp":"vertical"===z&&(o=(r-1+t.length)%t.length);break;case"ArrowDown":"vertical"===z&&(o=(r+1)%t.length);break;case"Enter":case" ":return void C(_);default:return}A(t[o])},orientation:z,ref:j,role:"tablist",size:D,tabIndex:-1},k("tab-list",v)),{children:[d,e(m,{})]})),"vertical"!==z&&B?F?e(g,{"data-role":"tab-navigation-button-right",id:"tab-navigation-button-right",onClick:()=>H("right"),size:D,tabIndex:-1,title:"Scroll Tabs Right",type:"button",children:e(w,{type:"chevron_right"})}):e(y,{size:D}):null]})})})),D=t=>{var{children:r,labelledBy:n="",orientation:o="horizontal",selectedTabId:i,size:l="medium"}=t,a=P(t,["children","labelledBy","orientation","selectedTabId","size"]);return e(s,{labelledBy:n,orientation:o,selectedTabId:i,size:l,children:e(u,T(S({id:"tabs-container",orientation:o},k("tabs",a)),{children:r}))})};export{A as Tab,C as TabList,z as TabPanel,D as Tabs,D as default};
@@ -1,4 +1,5 @@
1
1
  import React, { Dispatch, SetStateAction } from "react";
2
+ import { TagProps } from "../../../__internal__/utils/helpers/tags";
2
3
  export type TabValidationRecord = Record<string, string | boolean>;
3
4
  export type ValidationRecord = Record<string, TabValidationRecord>;
4
5
  export interface TabContextProps {
@@ -30,7 +31,7 @@ export interface TabsContextProps {
30
31
  infos: ValidationRecord;
31
32
  setInfos: (childId: string, tabId: string, info: string | boolean) => void;
32
33
  }
33
- export interface TabPanelProps {
34
+ export interface TabPanelProps extends TagProps {
34
35
  /** The content to be shown in the tab panel */
35
36
  children?: React.ReactNode;
36
37
  /** The ID of the tab panel */
@@ -38,7 +39,7 @@ export interface TabPanelProps {
38
39
  /** The ID of the controlling tab */
39
40
  tabId: string;
40
41
  }
41
- export interface TabListProps {
42
+ export interface TabListProps extends TagProps {
42
43
  /** The label read out when the tab list gains focus */
43
44
  ariaLabel: string;
44
45
  /** The tabs to be shown in the tab list */
@@ -46,7 +47,7 @@ export interface TabListProps {
46
47
  /** A callback for when the active tab is changed */
47
48
  onTabChange?: (tabId: string) => void;
48
49
  }
49
- export interface TabProps {
50
+ export interface TabProps extends TagProps {
50
51
  /** The tab panel that this tab controls */
51
52
  controls: string;
52
53
  /** The ID of the tab */
@@ -67,7 +68,7 @@ export interface TabProps {
67
68
  * */
68
69
  info?: boolean | string;
69
70
  }
70
- export interface TabsProps {
71
+ export interface TabsProps extends TagProps {
71
72
  /** The tab list to be rendered within this set of tabs */
72
73
  children?: React.ReactNode;
73
74
  /** The label associated with this set of tabs, for assistive technologies */
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { TabsHandle, TabListProps, TabPanelProps, TabProps, TabsProps } from "./tabs.types";
3
- export declare const TabPanel: ({ children, id, tabId }: TabPanelProps) => React.JSX.Element;
4
- export declare const Tab: ({ controls, error, id, label, leftSlot, rightSlot, warning, info, }: TabProps) => React.JSX.Element;
3
+ export declare const TabPanel: ({ children, id, tabId, ...rest }: TabPanelProps) => React.JSX.Element;
4
+ export declare const Tab: ({ controls, error, id, label, leftSlot, rightSlot, warning, info, ...rest }: TabProps) => React.JSX.Element;
5
5
  export declare const TabList: React.ForwardRefExoticComponent<TabListProps & React.RefAttributes<TabsHandle>>;
6
- export declare const Tabs: ({ children, labelledBy, orientation, selectedTabId, size, }: TabsProps) => React.JSX.Element;
6
+ export declare const Tabs: ({ children, labelledBy, orientation, selectedTabId, size, ...rest }: TabsProps) => React.JSX.Element;
7
7
  export default Tabs;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("./tabs.context.js"),a=require("./tabs.style.js"),n=require("../../../__internal__/utils/logger/index.js"),l=require("../../../hooks/__internal__/useResizeObserver/useResizeObserver.js"),i=require("../../../hooks/__internal__/useLocale/useLocale.js"),s=require("../../icon/icon.component.js"),o=require("./tab.context.js"),c=require("../../../hooks/__internal__/usePrevious/index.js");let u=!1;const d=t.forwardRef((({ariaLabel:n,children:i,onTabChange:o},u)=>{const d=t.useRef(null),{activeTab:b,focusIndex:f,orientation:h,selectedTabId:x,setFocusIndex:g,setActiveTab:p,size:v}=r.useTabs();t.useImperativeHandle(u,(()=>({focusTab:e=>{var t;const r=null===(t=d.current)||void 0===t?void 0:t.querySelector(`#${e}`);null==r||r.focus(),g(e),p(e)}})));const j=t.useCallback((()=>{var e;const t=(null===(e=d.current)||void 0===e?void 0:e.querySelectorAll("[role='tab']"))||[];return Array.from(t).map((e=>e.id)).filter((e=>e))}),[]);t.useEffect((()=>{if(x)p(x);else if(!b){const e=j()[0];p(e)}}),[b,j,x,p]);const y=c.default(b);t.useEffect((()=>{y&&y!==b&&(null==o||o(b))}),[b,o,y]);const[S,T]=t.useState(!1),[_,k]=t.useState(!1),[w,I]=t.useState(!1),m=t.useCallback((()=>{if(d.current){const e=d.current.scrollWidth-d.current.clientWidth-20;T(e>0),k(d.current.scrollLeft>=20),I(d.current.scrollLeft<=e)}}),[]);l.default(d,(()=>{m()})),t.useEffect((()=>{d.current&&m()}),[m]);const L=e=>{d.current&&("left"===e?d.current.scrollLeft-=200:d.current.scrollLeft+=200,m())};return e.jsx(e.Fragment,{children:e.jsxs(a.StyledTabListWrapper,{children:["vertical"!==h&&S?_?e.jsx(a.StyledScrollButton,{"data-role":"tab-navigation-button-left",id:"tab-navigation-button-left",onClick:()=>L("left"),size:v,tabIndex:-1,title:"Scroll Tabs Left",type:"button",children:e.jsx(s.default,{type:"chevron_left"})}):e.jsx(a.StyledScrollButtonPlaceholder,{size:v}):null,e.jsxs(a.StyledTabList,{"aria-label":n,id:"tablist",onKeyDown:e=>{const t=j(),r=t.indexOf(f||b),a=t.length-1;if(-1===r)return;let n=r;switch(e.key){case"Home":n=0;break;case"End":n=a;break;case"ArrowRight":n=(r+1)%t.length;break;case"ArrowLeft":n=(r-1+t.length)%t.length;break;case"ArrowUp":"vertical"===h&&(n=(r-1+t.length)%t.length);break;case"ArrowDown":"vertical"===h&&(n=(r+1)%t.length);break;case"Enter":case" ":return void p(b);default:return}g(t[n])},orientation:h,ref:d,role:"tablist",size:v,tabIndex:-1,children:[i,e.jsx(a.Spacer,{})]}),"vertical"!==h&&S?w?e.jsx(a.StyledScrollButton,{"data-role":"tab-navigation-button-right",id:"tab-navigation-button-right",onClick:()=>L("right"),size:v,tabIndex:-1,title:"Scroll Tabs Right",type:"button",children:e.jsx(s.default,{type:"chevron_right"})}):e.jsx(a.StyledScrollButtonPlaceholder,{size:v}):null]})})})),b=({children:t,labelledBy:n="",orientation:l="horizontal",selectedTabId:i,size:s="medium"})=>e.jsx(r.TabsProvider,{labelledBy:n,orientation:l,selectedTabId:i,size:s,children:e.jsx(a.StyledTabs,{id:"tabs-container",orientation:l,children:t})});exports.Tab=({controls:l,error:c=!1,id:d,label:b,leftSlot:f,rightSlot:h,warning:x=!1,info:g=!1})=>{const p=i.default(),[v,j]=t.useState(c),[y,S]=t.useState(x),[T,_]=t.useState(g),{activeTab:k,focusIndex:w,orientation:I,setActiveTab:m,setCurrentTabId:L,setFocusIndex:z,size:q,errors:P,warnings:A,infos:E}=r.useTabs(),B=k===d;t.useEffect((()=>{B&&L(d)}),[d,B,L]),!f&&!h||"string"==typeof b||u||(n.default.warn("[WARNING] Using `leftSlot` and/or `rightSlot` is not supported when `label` is not a string. Please use `leftSlot` and/or `rightSlot` alongside a string `label`, or use the `label` prop exclusively."),u=!0),t.useEffect((()=>{if(w===d){const e=document.getElementById(d);null==e||e.focus()}}),[w,d,L]),t.useEffect((()=>{let e=P[d],t=A[d],r=E[d];if(c&&!e&&(e={static:c}),x&&!t&&(t={static:x}),g&&!r&&(r={static:g}),!e)return void j(!1);const a=Object.keys(e).map((t=>e[t])).filter((e=>!1!==e)),n=c||a.length>0;if(j(n),!t)return void S(!1);const l=Object.keys(t).map((e=>t[e])).filter((e=>!1!==e)),i=x||l.length>0;if(S(i),!r)return void _(!1);const s=Object.keys(r).map((e=>r[e])).filter((e=>!1!==e)),o=g||s.length>0;_(o)}),[c,d,P,A,x,E,g]);const C=()=>{if(v||y||T){if(v)return e.jsx(s.default,{"data-role":"icon-error",type:"error",ariaLabel:p.tabs.error(),color:"#db004e"});if(y)return e.jsx(s.default,{"data-role":"icon-warning",type:"warning",ariaLabel:p.tabs.warning(),color:"#d64309"});if(T)return e.jsx(s.default,{"data-role":"icon-info",type:"info",ariaLabel:p.tabs.info(),color:"#0060a7ff"})}return null};return e.jsx(o.TabProvider,{tabId:d,visible:!0,children:e.jsx(a.StyledTab,{activeTab:k===d,"aria-controls":l,"aria-selected":B?"true":"false",error:v,info:T,id:d,onClick:()=>{m(d),z(d)},orientation:I,role:"tab",size:q,type:"button",tabIndex:k===d?0:-1,warning:y,children:"string"==typeof b?e.jsxs("span",{className:"tab-title-content-wrapper",children:[f,b,h,C()]}):e.jsxs("span",{className:"tab-title-content-wrapper",children:[b,C()]})})})},exports.TabList=d,exports.TabPanel=({children:t,id:n,tabId:l})=>{const{activeTab:i}=r.useTabs();return e.jsx(o.TabProvider,{tabId:l,visible:l===i,children:e.jsx(a.StyledTabPanel,{id:n,role:"tabpanel","aria-labelledby":l,children:t})})},exports.Tabs=b,exports.default=b;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("./tabs.context.js"),n=require("./tabs.style.js"),a=require("../../../__internal__/utils/logger/index.js"),l=require("../../../hooks/__internal__/useResizeObserver/useResizeObserver.js"),i=require("../../../hooks/__internal__/useLocale/useLocale.js"),o=require("../../icon/icon.component.js"),s=require("./tab.context.js"),c=require("../../../hooks/__internal__/usePrevious/index.js"),u=require("../../../__internal__/utils/helpers/tags/tags.js");function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){b(e,t,r[t])}))}return e}function f(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}function p(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)r=l[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)r=l[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}let h=!1;const y=t.forwardRef(((a,i)=>{var{ariaLabel:s,children:b,onTabChange:h}=a,y=p(a,["ariaLabel","children","onTabChange"]);const g=t.useRef(null),{activeTab:j,focusIndex:v,orientation:x,selectedTabId:S,setFocusIndex:O,setActiveTab:T,size:w}=r.useTabs();t.useImperativeHandle(i,(()=>({focusTab:e=>{var t;const r=null===(t=g.current)||void 0===t?void 0:t.querySelector(`#${e}`);null==r||r.focus(),O(e),T(e)}})));const m=t.useCallback((()=>{var e;const t=(null===(e=g.current)||void 0===e?void 0:e.querySelectorAll("[role='tab']"))||[];return Array.from(t).map((e=>e.id)).filter((e=>e))}),[]);t.useEffect((()=>{if(S)T(S);else if(!j){const e=m()[0];T(e)}}),[j,m,S,T]);const _=c.default(j);t.useEffect((()=>{_&&_!==j&&(null==h||h(j))}),[j,h,_]);const[P,k]=t.useState(!1),[I,L]=t.useState(!1),[z,q]=t.useState(!1),E=t.useCallback((()=>{if(g.current){const e=g.current.scrollWidth-g.current.clientWidth-20;k(e>0),L(g.current.scrollLeft>=20),q(g.current.scrollLeft<=e)}}),[]);l.default(g,(()=>{E()})),t.useEffect((()=>{g.current&&E()}),[E]);const A=e=>{g.current&&("left"===e?g.current.scrollLeft-=200:g.current.scrollLeft+=200,E())};return e.jsx(e.Fragment,{children:e.jsxs(n.StyledTabListWrapper,{children:["vertical"!==x&&P?I?e.jsx(n.StyledScrollButton,{"data-role":"tab-navigation-button-left",id:"tab-navigation-button-left",onClick:()=>A("left"),size:w,tabIndex:-1,title:"Scroll Tabs Left",type:"button",children:e.jsx(o.default,{type:"chevron_left"})}):e.jsx(n.StyledScrollButtonPlaceholder,{size:w}):null,e.jsxs(n.StyledTabList,f(d({"aria-label":s,id:"tablist",onKeyDown:e=>{const t=m(),r=t.indexOf(v||j),n=t.length-1;if(-1===r)return;let a=r;switch(e.key){case"Home":a=0;break;case"End":a=n;break;case"ArrowRight":a=(r+1)%t.length;break;case"ArrowLeft":a=(r-1+t.length)%t.length;break;case"ArrowUp":"vertical"===x&&(a=(r-1+t.length)%t.length);break;case"ArrowDown":"vertical"===x&&(a=(r+1)%t.length);break;case"Enter":case" ":return void T(j);default:return}O(t[a])},orientation:x,ref:g,role:"tablist",size:w,tabIndex:-1},u.default("tab-list",y)),{children:[b,e.jsx(n.Spacer,{})]})),"vertical"!==x&&P?z?e.jsx(n.StyledScrollButton,{"data-role":"tab-navigation-button-right",id:"tab-navigation-button-right",onClick:()=>A("right"),size:w,tabIndex:-1,title:"Scroll Tabs Right",type:"button",children:e.jsx(o.default,{type:"chevron_right"})}):e.jsx(n.StyledScrollButtonPlaceholder,{size:w}):null]})})})),g=t=>{var{children:a,labelledBy:l="",orientation:i="horizontal",selectedTabId:o,size:s="medium"}=t,c=p(t,["children","labelledBy","orientation","selectedTabId","size"]);return e.jsx(r.TabsProvider,{labelledBy:l,orientation:i,selectedTabId:o,size:s,children:e.jsx(n.StyledTabs,f(d({id:"tabs-container",orientation:i},u.default("tabs",c)),{children:a}))})};exports.Tab=l=>{var{controls:c,error:b=!1,id:y,label:g,leftSlot:j,rightSlot:v,warning:x=!1,info:S=!1}=l,O=p(l,["controls","error","id","label","leftSlot","rightSlot","warning","info"]);const T=i.default(),[w,m]=t.useState(b),[_,P]=t.useState(x),[k,I]=t.useState(S),{activeTab:L,focusIndex:z,orientation:q,setActiveTab:E,setCurrentTabId:A,setFocusIndex:B,size:C,errors:R,warnings:D,infos:N}=r.useTabs(),W=L===y;t.useEffect((()=>{W&&A(y)}),[y,W,A]),!j&&!v||"string"==typeof g||h||(a.default.warn("[WARNING] Using `leftSlot` and/or `rightSlot` is not supported when `label` is not a string. Please use `leftSlot` and/or `rightSlot` alongside a string `label`, or use the `label` prop exclusively."),h=!0),t.useEffect((()=>{if(z===y){const e=document.getElementById(y);null==e||e.focus()}}),[z,y,A]),t.useEffect((()=>{let e=R[y],t=D[y],r=N[y];if(b&&!e&&(e={static:b}),x&&!t&&(t={static:x}),S&&!r&&(r={static:S}),!e)return void m(!1);const n=Object.keys(e).map((t=>e[t])).filter((e=>!1!==e)),a=b||n.length>0;if(m(a),!t)return void P(!1);const l=Object.keys(t).map((e=>t[e])).filter((e=>!1!==e)),i=x||l.length>0;if(P(i),!r)return void I(!1);const o=Object.keys(r).map((e=>r[e])).filter((e=>!1!==e)),s=S||o.length>0;I(s)}),[b,y,R,D,x,N,S]);const F=()=>{if(w||_||k){if(w)return e.jsx(o.default,{"data-role":"icon-error",type:"error",ariaLabel:T.tabs.error(),color:"#db004e"});if(_)return e.jsx(o.default,{"data-role":"icon-warning",type:"warning",ariaLabel:T.tabs.warning(),color:"#d64309"});if(k)return e.jsx(o.default,{"data-role":"icon-info",type:"info",ariaLabel:T.tabs.info(),color:"#0060a7ff"})}return null};return e.jsx(s.TabProvider,{tabId:y,visible:!0,children:e.jsx(n.StyledTab,f(d({activeTab:L===y,"aria-controls":c,"aria-selected":W?"true":"false",error:w,info:k,id:y,onClick:()=>{E(y),B(y)},orientation:q,role:"tab",size:C,type:"button",tabIndex:L===y?0:-1,warning:_},u.default("tab",O)),{children:"string"==typeof g?e.jsxs("span",{className:"tab-title-content-wrapper",children:[j,g,v,F()]}):e.jsxs("span",{className:"tab-title-content-wrapper",children:[g,F()]})}))})},exports.TabList=y,exports.TabPanel=t=>{var{children:a,id:l,tabId:i}=t,o=p(t,["children","id","tabId"]);const{activeTab:c}=r.useTabs();return e.jsx(s.TabProvider,{tabId:i,visible:i===c,children:e.jsx(n.StyledTabPanel,f(d({id:l,role:"tabpanel","aria-labelledby":i},u.default("tab-panel",o)),{children:a}))})},exports.Tabs=g,exports.default=g;
@@ -1,4 +1,5 @@
1
1
  import React, { Dispatch, SetStateAction } from "react";
2
+ import { TagProps } from "../../../__internal__/utils/helpers/tags";
2
3
  export type TabValidationRecord = Record<string, string | boolean>;
3
4
  export type ValidationRecord = Record<string, TabValidationRecord>;
4
5
  export interface TabContextProps {
@@ -30,7 +31,7 @@ export interface TabsContextProps {
30
31
  infos: ValidationRecord;
31
32
  setInfos: (childId: string, tabId: string, info: string | boolean) => void;
32
33
  }
33
- export interface TabPanelProps {
34
+ export interface TabPanelProps extends TagProps {
34
35
  /** The content to be shown in the tab panel */
35
36
  children?: React.ReactNode;
36
37
  /** The ID of the tab panel */
@@ -38,7 +39,7 @@ export interface TabPanelProps {
38
39
  /** The ID of the controlling tab */
39
40
  tabId: string;
40
41
  }
41
- export interface TabListProps {
42
+ export interface TabListProps extends TagProps {
42
43
  /** The label read out when the tab list gains focus */
43
44
  ariaLabel: string;
44
45
  /** The tabs to be shown in the tab list */
@@ -46,7 +47,7 @@ export interface TabListProps {
46
47
  /** A callback for when the active tab is changed */
47
48
  onTabChange?: (tabId: string) => void;
48
49
  }
49
- export interface TabProps {
50
+ export interface TabProps extends TagProps {
50
51
  /** The tab panel that this tab controls */
51
52
  controls: string;
52
53
  /** The ID of the tab */
@@ -67,7 +68,7 @@ export interface TabProps {
67
68
  * */
68
69
  info?: boolean | string;
69
70
  }
70
- export interface TabsProps {
71
+ export interface TabsProps extends TagProps {
71
72
  /** The tab list to be rendered within this set of tabs */
72
73
  children?: React.ReactNode;
73
74
  /** The label associated with this set of tabs, for assistive technologies */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "158.25.2",
3
+ "version": "158.26.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",