@zag-js/tabs 0.49.0 → 0.50.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tabs.anatomy.ts","../src/tabs.connect.ts","../src/tabs.dom.ts","../src/tabs.machine.ts","../src/tabs.props.ts"],"sourcesContent":["import { createAnatomy } from \"@zag-js/anatomy\"\n\nexport const anatomy = createAnatomy(\"tabs\").parts(\"root\", \"list\", \"trigger\", \"content\", \"indicator\")\nexport const parts = anatomy.build()\n","import { getEventKey, getNativeEvent, type EventKeyMap } from \"@zag-js/dom-event\"\nimport { dataAttr, isSafari, isSelfTarget } from \"@zag-js/dom-query\"\nimport type { NormalizeProps, PropTypes } from \"@zag-js/types\"\nimport { parts } from \"./tabs.anatomy\"\nimport { dom } from \"./tabs.dom\"\nimport type { MachineApi, Send, State, TriggerProps, TriggerState } from \"./tabs.types\"\n\nexport function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T> {\n const translations = state.context.translations\n const focused = state.matches(\"focused\")\n\n function getTriggerState(props: TriggerProps): TriggerState {\n return {\n selected: state.context.value === props.value,\n focused: state.context.focusedValue === props.value,\n disabled: !!props.disabled,\n }\n }\n\n return {\n value: state.context.value,\n focusedValue: state.context.focusedValue,\n setValue(value) {\n send({ type: \"SET_VALUE\", value })\n },\n clearValue() {\n send({ type: \"CLEAR_VALUE\" })\n },\n setIndicatorRect(value) {\n const id = dom.getTriggerId(state.context, value)\n send({ type: \"SET_INDICATOR_RECT\", id })\n },\n getTriggerState,\n\n rootProps: normalize.element({\n ...parts.root.attrs,\n id: dom.getRootId(state.context),\n \"data-orientation\": state.context.orientation,\n \"data-focus\": dataAttr(focused),\n dir: state.context.dir,\n }),\n\n listProps: normalize.element({\n ...parts.list.attrs,\n id: dom.getListId(state.context),\n role: \"tablist\",\n dir: state.context.dir,\n \"data-focus\": dataAttr(focused),\n \"aria-orientation\": state.context.orientation,\n \"data-orientation\": state.context.orientation,\n \"aria-label\": translations.listLabel,\n onKeyDown(event) {\n if (event.defaultPrevented) return\n const evt = getNativeEvent(event)\n if (!isSelfTarget(evt)) return\n\n const keyMap: EventKeyMap = {\n ArrowDown() {\n send(\"ARROW_DOWN\")\n },\n ArrowUp() {\n send(\"ARROW_UP\")\n },\n ArrowLeft() {\n send(\"ARROW_LEFT\")\n },\n ArrowRight() {\n send(\"ARROW_RIGHT\")\n },\n Home() {\n send(\"HOME\")\n },\n End() {\n send(\"END\")\n },\n Enter() {\n send({ type: \"ENTER\", value: state.context.focusedValue })\n },\n }\n\n let key = getEventKey(event, state.context)\n const exec = keyMap[key]\n\n if (exec) {\n event.preventDefault()\n exec(event)\n }\n },\n }),\n\n getTriggerProps(props) {\n const { value, disabled } = props\n const triggerState = getTriggerState(props)\n\n return normalize.button({\n ...parts.trigger.attrs,\n role: \"tab\",\n type: \"button\",\n disabled,\n dir: state.context.dir,\n \"data-orientation\": state.context.orientation,\n \"data-disabled\": dataAttr(disabled),\n \"aria-disabled\": disabled,\n \"data-value\": value,\n \"aria-selected\": triggerState.selected,\n \"data-selected\": dataAttr(triggerState.selected),\n \"data-focus\": dataAttr(triggerState.focused),\n \"aria-controls\": dom.getContentId(state.context, value),\n \"data-ownedby\": dom.getListId(state.context),\n id: dom.getTriggerId(state.context, value),\n tabIndex: triggerState.selected ? 0 : -1,\n onFocus() {\n send({ type: \"TAB_FOCUS\", value })\n },\n onBlur(event) {\n const target = event.relatedTarget as HTMLElement | null\n if (target?.getAttribute(\"role\") !== \"tab\") {\n send({ type: \"TAB_BLUR\" })\n }\n },\n onClick(event) {\n if (event.defaultPrevented) return\n if (disabled) return\n if (isSafari()) {\n event.currentTarget.focus()\n }\n send({ type: \"TAB_CLICK\", value })\n },\n })\n },\n\n getContentProps(props) {\n const { value } = props\n const selected = state.context.value === value\n return normalize.element({\n ...parts.content.attrs,\n dir: state.context.dir,\n id: dom.getContentId(state.context, value),\n tabIndex: 0,\n \"aria-labelledby\": dom.getTriggerId(state.context, value),\n role: \"tabpanel\",\n \"data-ownedby\": dom.getListId(state.context),\n \"data-selected\": dataAttr(selected),\n \"data-orientation\": state.context.orientation,\n hidden: !selected,\n })\n },\n\n indicatorProps: normalize.element({\n id: dom.getIndicatorId(state.context),\n ...parts.indicator.attrs,\n dir: state.context.dir,\n \"data-orientation\": state.context.orientation,\n style: {\n \"--transition-property\": \"left, right, top, bottom, width, height\",\n \"--left\": state.context.indicatorRect?.left,\n \"--top\": state.context.indicatorRect?.top,\n \"--width\": state.context.indicatorRect?.width,\n \"--height\": state.context.indicatorRect?.height,\n position: \"absolute\",\n willChange: \"var(--transition-property)\",\n transitionProperty: \"var(--transition-property)\",\n transitionDuration: state.context.canIndicatorTransition ? \"var(--transition-duration, 150ms)\" : \"0ms\",\n transitionTimingFunction: \"var(--transition-timing-function)\",\n [state.context.orientation === \"horizontal\" ? \"left\" : \"top\"]:\n state.context.orientation === \"horizontal\" ? \"var(--left)\" : \"var(--top)\",\n },\n }),\n }\n}\n","import { createScope, itemById, nextById, prevById, queryAll } from \"@zag-js/dom-query\"\nimport { first, last } from \"@zag-js/utils\"\nimport type { MachineContext as Ctx } from \"./tabs.types\"\n\nexport const dom = createScope({\n getRootId: (ctx: Ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,\n getListId: (ctx: Ctx) => ctx.ids?.list ?? `tabs:${ctx.id}:list`,\n getContentId: (ctx: Ctx, id: string) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,\n getTriggerId: (ctx: Ctx, id: string) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,\n getIndicatorId: (ctx: Ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,\n\n getListEl: (ctx: Ctx) => dom.getById(ctx, dom.getListId(ctx)),\n getContentEl: (ctx: Ctx, id: string) => dom.getById(ctx, dom.getContentId(ctx, id)),\n getTriggerEl: (ctx: Ctx, id: string) => dom.getById(ctx, dom.getTriggerId(ctx, id)),\n getIndicatorEl: (ctx: Ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),\n\n getElements: (ctx: Ctx) => {\n const ownerId = CSS.escape(dom.getListId(ctx))\n const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`\n return queryAll(dom.getListEl(ctx), selector)\n },\n\n getFirstEl: (ctx: Ctx) => first(dom.getElements(ctx)),\n getLastEl: (ctx: Ctx) => last(dom.getElements(ctx)),\n getNextEl: (ctx: Ctx, id: string) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),\n getPrevEl: (ctx: Ctx, id: string) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),\n getActiveContentEl: (ctx: Ctx) => {\n if (!ctx.value) return\n return dom.getContentEl(ctx, ctx.value)\n },\n getActiveTabEl: (ctx: Ctx) => {\n if (!ctx.value) return\n return dom.getTriggerEl(ctx, ctx.value)\n },\n\n getOffsetRect: (el: HTMLElement | undefined) => {\n return {\n left: el?.offsetLeft ?? 0,\n top: el?.offsetTop ?? 0,\n width: el?.offsetWidth ?? 0,\n height: el?.offsetHeight ?? 0,\n }\n },\n\n getRectById: (ctx: Ctx, id: string) => {\n const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))\n return dom.resolveRect(dom.getOffsetRect(tab))\n },\n\n resolveRect: (rect: Record<\"width\" | \"height\" | \"left\" | \"top\", number>) => ({\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n left: `${rect.left}px`,\n top: `${rect.top}px`,\n }),\n})\n","import { createMachine, guards } from \"@zag-js/core\"\nimport { clickIfLink } from \"@zag-js/dom-event\"\nimport { nextTick, raf } from \"@zag-js/dom-query\"\nimport { trackElementRect } from \"@zag-js/element-rect\"\nimport { getFocusables } from \"@zag-js/tabbable\"\nimport { compact, isEqual } from \"@zag-js/utils\"\nimport { dom } from \"./tabs.dom\"\nimport type { MachineContext, MachineState, UserDefinedContext } from \"./tabs.types\"\n\nconst { not } = guards\n\nexport function machine(userContext: UserDefinedContext) {\n const ctx = compact(userContext)\n return createMachine<MachineContext, MachineState>(\n {\n initial: \"idle\",\n\n context: {\n dir: \"ltr\",\n orientation: \"horizontal\",\n activationMode: \"automatic\",\n value: null,\n focusedValue: null,\n indicatorRect: {\n left: \"0px\",\n top: \"0px\",\n width: \"0px\",\n height: \"0px\",\n },\n canIndicatorTransition: false,\n isIndicatorRendered: false,\n loopFocus: true,\n translations: {},\n ...ctx,\n },\n\n computed: {\n isHorizontal: (ctx) => ctx.orientation === \"horizontal\",\n isVertical: (ctx) => ctx.orientation === \"vertical\",\n },\n\n entry: [\"checkRenderedElements\", \"syncIndicatorRect\", \"setContentTabIndex\"],\n\n exit: [\"cleanupObserver\"],\n\n watch: {\n value: [\"enableIndicatorTransition\", \"syncIndicatorRect\", \"setContentTabIndex\", \"clickIfLink\"],\n dir: [\"syncIndicatorRect\"],\n orientation: [\"syncIndicatorRect\"],\n },\n\n on: {\n SET_VALUE: {\n actions: \"setValue\",\n },\n CLEAR_VALUE: {\n actions: \"clearValue\",\n },\n SET_INDICATOR_RECT: {\n actions: \"setIndicatorRect\",\n },\n },\n\n states: {\n idle: {\n on: {\n TAB_FOCUS: [\n {\n guard: \"selectOnFocus\",\n target: \"focused\",\n actions: [\"setFocusedValue\", \"setValue\"],\n },\n {\n target: \"focused\",\n actions: \"setFocusedValue\",\n },\n ],\n TAB_CLICK: {\n target: \"focused\",\n actions: [\"setFocusedValue\", \"setValue\"],\n },\n },\n },\n focused: {\n on: {\n TAB_CLICK: {\n target: \"focused\",\n actions: [\"setFocusedValue\", \"setValue\"],\n },\n ARROW_LEFT: {\n guard: \"isHorizontal\",\n actions: \"focusPrevTab\",\n },\n ARROW_RIGHT: {\n guard: \"isHorizontal\",\n actions: \"focusNextTab\",\n },\n ARROW_UP: {\n guard: \"isVertical\",\n actions: \"focusPrevTab\",\n },\n ARROW_DOWN: {\n guard: \"isVertical\",\n actions: \"focusNextTab\",\n },\n HOME: {\n actions: \"focusFirstTab\",\n },\n END: {\n actions: \"focusLastTab\",\n },\n ENTER: {\n guard: not(\"selectOnFocus\"),\n actions: \"setValue\",\n },\n TAB_FOCUS: [\n {\n guard: \"selectOnFocus\",\n actions: [\"setFocusedValue\", \"setValue\"],\n },\n { actions: \"setFocusedValue\" },\n ],\n TAB_BLUR: {\n target: \"idle\",\n actions: \"clearFocusedValue\",\n },\n },\n },\n },\n },\n {\n guards: {\n isVertical: (ctx) => ctx.isVertical,\n isHorizontal: (ctx) => ctx.isHorizontal,\n selectOnFocus: (ctx) => ctx.activationMode === \"automatic\",\n },\n\n actions: {\n setFocusedValue(ctx, evt) {\n set.focusedValue(ctx, evt.value)\n },\n clearFocusedValue(ctx) {\n set.focusedValue(ctx, null)\n },\n setValue(ctx, evt) {\n set.value(ctx, evt.value)\n },\n clearValue(ctx) {\n set.value(ctx, null)\n },\n focusFirstTab(ctx) {\n raf(() => dom.getFirstEl(ctx)?.focus())\n },\n focusLastTab(ctx) {\n raf(() => dom.getLastEl(ctx)?.focus())\n },\n focusNextTab(ctx) {\n if (!ctx.focusedValue) return\n const next = dom.getNextEl(ctx, ctx.focusedValue)\n raf(() => next?.focus())\n },\n focusPrevTab(ctx) {\n if (!ctx.focusedValue) return\n const prev = dom.getPrevEl(ctx, ctx.focusedValue)\n raf(() => prev?.focus())\n },\n checkRenderedElements(ctx) {\n ctx.isIndicatorRendered = !!dom.getIndicatorEl(ctx)\n },\n // if tab panel contains focusable elements, remove the tabindex attribute\n setContentTabIndex(ctx) {\n raf(() => {\n const panel = dom.getActiveContentEl(ctx)\n if (!panel) return\n const focusables = getFocusables(panel)\n if (focusables.length > 0) {\n panel.removeAttribute(\"tabindex\")\n } else {\n panel.setAttribute(\"tabindex\", \"0\")\n }\n })\n },\n cleanupObserver(ctx) {\n ctx.indicatorCleanup?.()\n },\n enableIndicatorTransition(ctx) {\n ctx.canIndicatorTransition = true\n },\n setIndicatorRect(ctx, evt) {\n const value = evt.id ?? ctx.value\n if (!ctx.isIndicatorRendered || !value) return\n\n const tabEl = dom.getTriggerEl(ctx, value)\n if (!tabEl) return\n\n ctx.indicatorRect = dom.getRectById(ctx, value)\n nextTick(() => {\n ctx.canIndicatorTransition = false\n })\n },\n syncIndicatorRect(ctx) {\n ctx.indicatorCleanup?.()\n\n const value = ctx.value\n if (!ctx.isIndicatorRendered || !value) return\n\n const tabEl = dom.getActiveTabEl(ctx)\n if (!tabEl) return\n\n ctx.indicatorCleanup = trackElementRect(tabEl, {\n getRect(el) {\n return dom.getOffsetRect(el)\n },\n onChange(rect) {\n ctx.indicatorRect = dom.resolveRect(rect)\n nextTick(() => {\n ctx.canIndicatorTransition = false\n })\n },\n })\n },\n clickIfLink(ctx) {\n clickIfLink(dom.getActiveTabEl(ctx))\n },\n },\n },\n )\n}\n\nconst invoke = {\n change: (ctx: MachineContext) => {\n if (ctx.value == null) return\n ctx.onValueChange?.({ value: ctx.value })\n },\n focusChange: (ctx: MachineContext) => {\n if (ctx.focusedValue == null) return\n ctx.onFocusChange?.({ focusedValue: ctx.focusedValue })\n },\n}\n\nconst set = {\n value: (ctx: MachineContext, value: string | null) => {\n if (isEqual(value, ctx.value)) return\n ctx.value = value\n invoke.change(ctx)\n },\n focusedValue: (ctx: MachineContext, value: string | null) => {\n if (isEqual(value, ctx.focusedValue)) return\n ctx.focusedValue = value\n invoke.focusChange(ctx)\n },\n}\n","import { createProps } from \"@zag-js/types\"\nimport { createSplitProps } from \"@zag-js/utils\"\nimport type { ContentProps, TriggerProps, UserDefinedContext } from \"./tabs.types\"\n\nexport const props = createProps<UserDefinedContext>()([\n \"activationMode\",\n \"dir\",\n \"getRootNode\",\n \"id\",\n \"ids\",\n \"loopFocus\",\n \"onFocusChange\",\n \"onValueChange\",\n \"orientation\",\n \"translations\",\n \"value\",\n])\n\nexport const splitProps = createSplitProps<Partial<UserDefinedContext>>(props)\n\nexport const triggerProps = createProps<TriggerProps>()([\"disabled\", \"value\"])\nexport const splitTriggerProps = createSplitProps<TriggerProps>(triggerProps)\n\nexport const contentProps = createProps<ContentProps>()([\"value\"])\nexport const splitContentProps = createSplitProps<ContentProps>(contentProps)\n"],"mappings":";AAAA,SAAS,qBAAqB;AAEvB,IAAM,UAAU,cAAc,MAAM,EAAE,MAAM,QAAQ,QAAQ,WAAW,WAAW,WAAW;AAC7F,IAAM,QAAQ,QAAQ,MAAM;;;ACHnC,SAAS,aAAa,sBAAwC;AAC9D,SAAS,UAAU,UAAU,oBAAoB;;;ACDjD,SAAS,aAAa,UAAU,UAAU,UAAU,gBAAgB;AACpE,SAAS,OAAO,YAAY;AAGrB,IAAM,MAAM,YAAY;AAAA,EAC7B,WAAW,CAAC,QAAa,IAAI,KAAK,QAAQ,QAAQ,IAAI,EAAE;AAAA,EACxD,WAAW,CAAC,QAAa,IAAI,KAAK,QAAQ,QAAQ,IAAI,EAAE;AAAA,EACxD,cAAc,CAAC,KAAU,OAAe,IAAI,KAAK,WAAW,QAAQ,IAAI,EAAE,YAAY,EAAE;AAAA,EACxF,cAAc,CAAC,KAAU,OAAe,IAAI,KAAK,WAAW,QAAQ,IAAI,EAAE,YAAY,EAAE;AAAA,EACxF,gBAAgB,CAAC,QAAa,IAAI,KAAK,aAAa,QAAQ,IAAI,EAAE;AAAA,EAElE,WAAW,CAAC,QAAa,IAAI,QAAQ,KAAK,IAAI,UAAU,GAAG,CAAC;AAAA,EAC5D,cAAc,CAAC,KAAU,OAAe,IAAI,QAAQ,KAAK,IAAI,aAAa,KAAK,EAAE,CAAC;AAAA,EAClF,cAAc,CAAC,KAAU,OAAe,IAAI,QAAQ,KAAK,IAAI,aAAa,KAAK,EAAE,CAAC;AAAA,EAClF,gBAAgB,CAAC,QAAa,IAAI,QAAQ,KAAK,IAAI,eAAe,GAAG,CAAC;AAAA,EAEtE,aAAa,CAAC,QAAa;AACzB,UAAM,UAAU,IAAI,OAAO,IAAI,UAAU,GAAG,CAAC;AAC7C,UAAM,WAAW,4BAA4B,OAAO;AACpD,WAAO,S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b,QAAQ,CAAC,QAAwB;AAC/B,QAAI,IAAI,SAAS;AAAM;AACvB,QAAI,gBAAgB,EAAE,OAAO,IAAI,MAAM,CAAC;AAAA,EAC1C;AAAA,EACA,aAAa,CAAC,QAAwB;AACpC,QAAI,IAAI,gBAAgB;AAAM;AAC9B,QAAI,gBAAgB,EAAE,cAAc,IAAI,aAAa,CAAC;AAAA,EACxD;AACF;AAEA,IAAM,MAAM;AAAA,EACV,OAAO,CAAC,KAAqB,UAAyB;AACpD,QAAI,QAAQ,OAAO,IAAI,KAAK;AAAG;AAC/B,QAAI,QAAQ;AACZ,WAAO,OAAO,GAAG;AAAA,EACnB;AAAA,EACA,cAAc,CAAC,KAAqB,UAAyB;AAC3D,QAAI,QAAQ,OAAO,IAAI,YAAY;AAAG;AACtC,QAAI,eAAe;AACnB,WAAO,YAAY,GAAG;AAAA,EACxB;AACF;;;AC3PA,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AAG1B,IAAM,QAAQ,YAAgC,EAAE;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,aAAa,iBAA8C,KAAK;AAEtE,IAAM,eAAe,YAA0B,EAAE,CAAC,YAAY,OAAO,CAAC;AACtE,IAAM,oBAAoB,iBAA+B,YAAY;AAErE,IAAM,eAAe,YAA0B,EAAE,CAAC,OAAO,CAAC;AAC1D,IAAM,oBAAoB,iBAA+B,YAAY;","names":["props","ctx"]}
1
+ {"version":3,"sources":["../src/tabs.anatomy.ts","../src/tabs.connect.ts","../src/tabs.dom.ts","../src/tabs.machine.ts","../src/tabs.props.ts"],"sourcesContent":["import { createAnatomy } from \"@zag-js/anatomy\"\n\nexport const anatomy = createAnatomy(\"tabs\").parts(\"root\", \"list\", \"trigger\", \"content\", \"indicator\")\nexport const parts = anatomy.build()\n","import { getEventKey, getNativeEvent, type EventKeyMap } from \"@zag-js/dom-event\"\nimport { dataAttr, isSafari, isSelfTarget } from \"@zag-js/dom-query\"\nimport type { NormalizeProps, PropTypes } from \"@zag-js/types\"\nimport { parts } from \"./tabs.anatomy\"\nimport { dom } from \"./tabs.dom\"\nimport type { MachineApi, Send, State, TriggerProps, TriggerState } from \"./tabs.types\"\n\nexport function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T> {\n const translations = state.context.translations\n const focused = state.matches(\"focused\")\n\n const isVertical = state.context.orientation === \"vertical\"\n const isHorizontal = state.context.orientation === \"horizontal\"\n const composite = state.context.composite\n const indicator = state.context.indicatorState\n\n function getTriggerState(props: TriggerProps): TriggerState {\n return {\n selected: state.context.value === props.value,\n focused: state.context.focusedValue === props.value,\n disabled: !!props.disabled,\n }\n }\n\n return {\n value: state.context.value,\n focusedValue: state.context.focusedValue,\n setValue(value) {\n send({ type: \"SET_VALUE\", value })\n },\n clearValue() {\n send({ type: \"CLEAR_VALUE\" })\n },\n setIndicatorRect(value) {\n const id = dom.getTriggerId(state.context, value)\n send({ type: \"SET_INDICATOR_RECT\", id })\n },\n syncTabIndex() {\n send(\"SYNC_TAB_INDEX\")\n },\n selectNext(fromValue) {\n send({ type: \"TAB_FOCUS\", value: fromValue, src: \"selectNext\" })\n send({ type: \"ARROW_NEXT\", src: \"selectNext\" })\n },\n selectPrev(fromValue) {\n send({ type: \"TAB_FOCUS\", value: fromValue, src: \"selectPrev\" })\n send({ type: \"ARROW_PREV\", src: \"selectPrev\" })\n },\n focus() {\n dom.getSelectedTriggerEl(state.context)?.focus()\n },\n getTriggerState,\n\n rootProps: normalize.element({\n ...parts.root.attrs,\n id: dom.getRootId(state.context),\n \"data-orientation\": state.context.orientation,\n \"data-focus\": dataAttr(focused),\n dir: state.context.dir,\n }),\n\n listProps: normalize.element({\n ...parts.list.attrs,\n id: dom.getListId(state.context),\n role: \"tablist\",\n dir: state.context.dir,\n \"data-focus\": dataAttr(focused),\n \"aria-orientation\": state.context.orientation,\n \"data-orientation\": state.context.orientation,\n \"aria-label\": translations?.listLabel,\n onKeyDown(event) {\n if (event.defaultPrevented) return\n const evt = getNativeEvent(event)\n\n if (!isSelfTarget(evt)) return\n if (evt.isComposing) return\n\n const keyMap: EventKeyMap = {\n ArrowDown() {\n if (isHorizontal) return\n send({ type: \"ARROW_NEXT\", key: \"ArrowDown\" })\n },\n ArrowUp() {\n if (isHorizontal) return\n send({ type: \"ARROW_PREV\", key: \"ArrowUp\" })\n },\n ArrowLeft() {\n if (isVertical) return\n send({ type: \"ARROW_PREV\", key: \"ArrowLeft\" })\n },\n ArrowRight() {\n if (isVertical) return\n send({ type: \"ARROW_NEXT\", key: \"ArrowRight\" })\n },\n Home() {\n send(\"HOME\")\n },\n End() {\n send(\"END\")\n },\n Enter() {\n send({ type: \"ENTER\" })\n },\n }\n\n let key = getEventKey(event, state.context)\n const exec = keyMap[key]\n\n if (exec) {\n event.preventDefault()\n exec(event)\n }\n },\n }),\n\n getTriggerProps(props) {\n const { value, disabled } = props\n const triggerState = getTriggerState(props)\n\n return normalize.button({\n ...parts.trigger.attrs,\n role: \"tab\",\n type: \"button\",\n disabled,\n dir: state.context.dir,\n \"data-orientation\": state.context.orientation,\n \"data-disabled\": dataAttr(disabled),\n \"aria-disabled\": disabled,\n \"data-value\": value,\n \"aria-selected\": triggerState.selected,\n \"data-selected\": dataAttr(triggerState.selected),\n \"data-focus\": dataAttr(triggerState.focused),\n \"aria-controls\": triggerState.selected ? dom.getContentId(state.context, value) : undefined,\n \"data-ownedby\": dom.getListId(state.context),\n id: dom.getTriggerId(state.context, value),\n tabIndex: triggerState.selected && composite ? 0 : -1,\n onFocus() {\n send({ type: \"TAB_FOCUS\", value })\n },\n onBlur(event) {\n const target = event.relatedTarget as HTMLElement | null\n if (target?.getAttribute(\"role\") !== \"tab\") {\n send({ type: \"TAB_BLUR\" })\n }\n },\n onClick(event) {\n if (event.defaultPrevented) return\n if (disabled) return\n if (isSafari()) {\n event.currentTarget.focus()\n }\n send({ type: \"TAB_CLICK\", value })\n },\n })\n },\n\n getContentProps(props) {\n const { value } = props\n const selected = state.context.value === value\n return normalize.element({\n ...parts.content.attrs,\n dir: state.context.dir,\n id: dom.getContentId(state.context, value),\n tabIndex: composite ? 0 : -1,\n \"aria-labelledby\": dom.getTriggerId(state.context, value),\n role: \"tabpanel\",\n \"data-ownedby\": dom.getListId(state.context),\n \"data-selected\": dataAttr(selected),\n \"data-orientation\": state.context.orientation,\n hidden: !selected,\n })\n },\n\n indicatorProps: normalize.element({\n id: dom.getIndicatorId(state.context),\n ...parts.indicator.attrs,\n dir: state.context.dir,\n \"data-orientation\": state.context.orientation,\n style: {\n \"--transition-property\": \"left, right, top, bottom, width, height\",\n \"--left\": indicator.rect?.left,\n \"--top\": indicator.rect?.top,\n \"--width\": indicator.rect?.width,\n \"--height\": indicator.rect?.height,\n position: \"absolute\",\n willChange: \"var(--transition-property)\",\n transitionProperty: \"var(--transition-property)\",\n transitionDuration: indicator.transition ? \"var(--transition-duration, 150ms)\" : \"0ms\",\n transitionTimingFunction: \"var(--transition-timing-function)\",\n [isHorizontal ? \"left\" : \"top\"]: isHorizontal ? \"var(--left)\" : \"var(--top)\",\n },\n }),\n }\n}\n","import { createScope, itemById, nextById, prevById, queryAll } from \"@zag-js/dom-query\"\nimport { first, last } from \"@zag-js/utils\"\nimport type { MachineContext as Ctx } from \"./tabs.types\"\n\nexport const dom = createScope({\n getRootId: (ctx: Ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,\n getListId: (ctx: Ctx) => ctx.ids?.list ?? `tabs:${ctx.id}:list`,\n getContentId: (ctx: Ctx, id: string) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,\n getTriggerId: (ctx: Ctx, id: string) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,\n getIndicatorId: (ctx: Ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,\n\n getListEl: (ctx: Ctx) => dom.getById(ctx, dom.getListId(ctx)),\n getContentEl: (ctx: Ctx, id: string) => dom.getById(ctx, dom.getContentId(ctx, id)),\n getTriggerEl: (ctx: Ctx, id: string) => dom.getById(ctx, dom.getTriggerId(ctx, id)),\n getIndicatorEl: (ctx: Ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),\n\n getElements: (ctx: Ctx) => {\n const ownerId = CSS.escape(dom.getListId(ctx))\n const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`\n return queryAll(dom.getListEl(ctx), selector)\n },\n\n getFirstTriggerEl: (ctx: Ctx) => first(dom.getElements(ctx)),\n getLastTriggerEl: (ctx: Ctx) => last(dom.getElements(ctx)),\n getNextTriggerEl: (ctx: Ctx, id: string) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),\n getPrevTriggerEl: (ctx: Ctx, id: string) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),\n getSelectedContentEl: (ctx: Ctx) => {\n if (!ctx.value) return\n return dom.getContentEl(ctx, ctx.value)\n },\n getSelectedTriggerEl: (ctx: Ctx) => {\n if (!ctx.value) return\n return dom.getTriggerEl(ctx, ctx.value)\n },\n\n getOffsetRect: (el: HTMLElement | undefined) => {\n return {\n left: el?.offsetLeft ?? 0,\n top: el?.offsetTop ?? 0,\n width: el?.offsetWidth ?? 0,\n height: el?.offsetHeight ?? 0,\n }\n },\n\n getRectById: (ctx: Ctx, id: string) => {\n const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))\n return dom.resolveRect(dom.getOffsetRect(tab))\n },\n\n resolveRect: (rect: Record<\"width\" | \"height\" | \"left\" | \"top\", number>) => ({\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n left: `${rect.left}px`,\n top: `${rect.top}px`,\n }),\n})\n","import { createMachine, guards } from \"@zag-js/core\"\nimport { clickIfLink } from \"@zag-js/dom-event\"\nimport { nextTick, raf, getFocusables } from \"@zag-js/dom-query\"\nimport { trackElementRect } from \"@zag-js/element-rect\"\nimport { compact, isEqual } from \"@zag-js/utils\"\nimport { dom } from \"./tabs.dom\"\nimport type { MachineContext, MachineState, UserDefinedContext } from \"./tabs.types\"\n\nconst { not } = guards\n\nexport function machine(userContext: UserDefinedContext) {\n const ctx = compact(userContext)\n return createMachine<MachineContext, MachineState>(\n {\n initial: \"idle\",\n\n context: {\n dir: \"ltr\",\n orientation: \"horizontal\",\n activationMode: \"automatic\",\n value: null,\n loopFocus: true,\n composite: true,\n ...ctx,\n focusedValue: ctx.value ?? null,\n indicatorState: {\n rendered: false,\n transition: false,\n rect: { left: \"0px\", top: \"0px\", width: \"0px\", height: \"0px\" },\n },\n },\n\n watch: {\n value: [\"allowIndicatorTransition\", \"syncIndicatorRect\", \"syncTabIndex\", \"clickIfLink\"],\n dir: [\"syncIndicatorRect\"],\n orientation: [\"syncIndicatorRect\"],\n },\n\n on: {\n SET_VALUE: {\n actions: \"setValue\",\n },\n CLEAR_VALUE: {\n actions: \"clearValue\",\n },\n SET_INDICATOR_RECT: {\n actions: \"setIndicatorRect\",\n },\n SYNC_TAB_INDEX: {\n actions: \"syncTabIndex\",\n },\n },\n\n created: [\"syncFocusedValue\"],\n entry: [\"checkRenderedElements\", \"syncIndicatorRect\", \"syncTabIndex\"],\n exit: [\"cleanupObserver\"],\n\n states: {\n idle: {\n on: {\n TAB_FOCUS: {\n target: \"focused\",\n actions: \"setFocusedValue\",\n },\n TAB_CLICK: {\n target: \"focused\",\n actions: [\"setFocusedValue\", \"setValue\"],\n },\n },\n },\n focused: {\n on: {\n TAB_CLICK: {\n target: \"focused\",\n actions: [\"setFocusedValue\", \"setValue\"],\n },\n ARROW_PREV: [\n {\n guard: \"selectOnFocus\",\n actions: [\"focusPrevTab\", \"selectFocusedTab\"],\n },\n {\n actions: \"focusPrevTab\",\n },\n ],\n ARROW_NEXT: [\n {\n guard: \"selectOnFocus\",\n actions: [\"focusNextTab\", \"selectFocusedTab\"],\n },\n {\n actions: \"focusNextTab\",\n },\n ],\n HOME: [\n {\n guard: \"selectOnFocus\",\n actions: [\"focusFirstTab\", \"selectFocusedTab\"],\n },\n {\n actions: \"focusFirstTab\",\n },\n ],\n END: [\n {\n guard: \"selectOnFocus\",\n actions: [\"focusLastTab\", \"selectFocusedTab\"],\n },\n {\n actions: \"focusLastTab\",\n },\n ],\n ENTER: {\n guard: not(\"selectOnFocus\"),\n actions: \"selectFocusedTab\",\n },\n TAB_FOCUS: {\n actions: [\"setFocusedValue\"],\n },\n TAB_BLUR: {\n target: \"idle\",\n actions: \"clearFocusedValue\",\n },\n },\n },\n },\n },\n {\n guards: {\n selectOnFocus: (ctx) => ctx.activationMode === \"automatic\",\n },\n\n actions: {\n syncFocusedValue(ctx) {\n if (ctx.value != null && ctx.focusedValue == null) {\n ctx.focusedValue = ctx.value\n }\n },\n selectFocusedTab(ctx) {\n raf(() => {\n set.value(ctx, ctx.focusedValue)\n })\n },\n setFocusedValue(ctx, evt) {\n if (evt.value == null) return\n set.focusedValue(ctx, evt.value)\n },\n clearFocusedValue(ctx) {\n set.focusedValue(ctx, null)\n },\n setValue(ctx, evt) {\n set.value(ctx, evt.value)\n },\n clearValue(ctx) {\n set.value(ctx, null)\n },\n focusFirstTab(ctx) {\n raf(() => {\n dom.getFirstTriggerEl(ctx)?.focus()\n })\n },\n focusLastTab(ctx) {\n raf(() => {\n dom.getLastTriggerEl(ctx)?.focus()\n })\n },\n focusNextTab(ctx) {\n if (!ctx.focusedValue) return\n const triggerEl = dom.getNextTriggerEl(ctx, ctx.focusedValue)\n raf(() => {\n if (ctx.composite) {\n triggerEl?.focus()\n } else if (triggerEl?.dataset.value != null) {\n set.focusedValue(ctx, triggerEl.dataset.value)\n }\n })\n },\n focusPrevTab(ctx) {\n if (!ctx.focusedValue) return\n const triggerEl = dom.getPrevTriggerEl(ctx, ctx.focusedValue)\n raf(() => {\n if (ctx.composite) {\n triggerEl?.focus()\n } else if (triggerEl?.dataset.value != null) {\n set.focusedValue(ctx, triggerEl.dataset.value)\n }\n })\n },\n checkRenderedElements(ctx) {\n ctx.indicatorState.rendered = !!dom.getIndicatorEl(ctx)\n },\n syncTabIndex(ctx) {\n raf(() => {\n const contentEl = dom.getSelectedContentEl(ctx)\n if (!contentEl) return\n const focusables = getFocusables(contentEl)\n if (focusables.length > 0) {\n contentEl.removeAttribute(\"tabindex\")\n } else {\n contentEl.setAttribute(\"tabindex\", \"0\")\n }\n })\n },\n cleanupObserver(ctx) {\n ctx.indicatorCleanup?.()\n },\n allowIndicatorTransition(ctx) {\n ctx.indicatorState.transition = true\n },\n setIndicatorRect(ctx, evt) {\n const value = evt.id ?? ctx.value\n if (!ctx.indicatorState.rendered || !value) return\n\n const triggerEl = dom.getTriggerEl(ctx, value)\n if (!triggerEl) return\n\n ctx.indicatorState.rect = dom.getRectById(ctx, value)\n nextTick(() => {\n ctx.indicatorState.transition = false\n })\n },\n syncIndicatorRect(ctx) {\n ctx.indicatorCleanup?.()\n\n const value = ctx.value\n if (!ctx.indicatorState.rendered || !value) return\n\n const triggerEl = dom.getSelectedTriggerEl(ctx)\n if (!triggerEl) return\n\n ctx.indicatorCleanup = trackElementRect(triggerEl, {\n getRect(el) {\n return dom.getOffsetRect(el)\n },\n onChange(rect) {\n ctx.indicatorState.rect = dom.resolveRect(rect)\n nextTick(() => {\n ctx.indicatorState.transition = false\n })\n },\n })\n },\n clickIfLink(ctx) {\n clickIfLink(dom.getSelectedTriggerEl(ctx))\n },\n },\n },\n )\n}\n\nconst invoke = {\n change: (ctx: MachineContext) => {\n if (ctx.value == null) return\n ctx.onValueChange?.({ value: ctx.value })\n },\n focusChange: (ctx: MachineContext) => {\n if (ctx.focusedValue == null) return\n ctx.onFocusChange?.({ focusedValue: ctx.focusedValue })\n },\n}\n\nconst set = {\n value: (ctx: MachineContext, value: string | null) => {\n if (isEqual(value, ctx.value)) return\n ctx.value = value\n invoke.change(ctx)\n },\n focusedValue: (ctx: MachineContext, value: string | null) => {\n if (isEqual(value, ctx.focusedValue)) return\n ctx.focusedValue = value\n invoke.focusChange(ctx)\n },\n}\n","import { createProps } from \"@zag-js/types\"\nimport { createSplitProps } from \"@zag-js/utils\"\nimport type { ContentProps, TriggerProps, UserDefinedContext } from \"./tabs.types\"\n\nexport const props = createProps<UserDefinedContext>()([\n \"activationMode\",\n \"composite\",\n \"dir\",\n \"getRootNode\",\n \"id\",\n \"ids\",\n \"loopFocus\",\n \"onFocusChange\",\n \"onValueChange\",\n \"orientation\",\n \"translations\",\n \"value\",\n])\n\nexport const splitProps = createSplitProps<Partial<UserDefinedContext>>(props)\n\nexport const triggerProps = createProps<TriggerProps>()([\"disabled\", \"value\"])\nexport const splitTriggerProps = createSplitProps<TriggerProps>(triggerProps)\n\nexport const contentProps = createProps<ContentProps>()([\"value\"])\nexport const splitContentProps = createSplitProps<ContentProps>(contentProps)\n"],"mappings":";AAAA,SAAS,qBAAqB;AAEvB,IAAM,UAAU,cAAc,MAAM,EAAE,MAAM,QAAQ,QAAQ,WAAW,WAAW,WAAW;AAC7F,IAAM,QAAQ,QAAQ,MAAM;;;ACHnC,SAAS,aAAa,sBAAwC;AAC9D,SAAS,UAAU,UAAU,oBAAoB;;;ACDjD,SAAS,aAAa,UAAU,UAAU,UAAU,gBAAgB;AACpE,SAAS,OAAO,YAAY;AAGrB,IAAM,MAAM,YAAY;AAAA,EAC7B,WAAW,CAAC,QAAa,IAAI,KAAK,QAAQ,QAAQ,IAAI,EAAE;AAAA,EACxD,WAAW,CAAC,QAAa,IAAI,KAAK,QAAQ,QAAQ,IAAI,EAAE;AAAA,EACxD,cAAc,CAAC,KAAU,OAAe,IAAI,KAAK,WAAW,QAAQ,IAAI,EAAE,YAAY,EAAE;AAAA,EACxF,cAAc,CAAC,KAAU,OAAe,IAAI,KAAK,WAAW,QAAQ,IAAI,EAAE,YAAY,EAAE;AAAA,EACxF,gBAAgB,CAAC,QAAa,IAAI,KAAK,aAAa,QAAQ,IAAI,EAAE;AAAA,EAElE,WAAW,CAAC,QAAa,IAAI,QAA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A;AACF,CAAC;AAEM,IAAM,aAAa,iBAA8C,KAAK;AAEtE,IAAM,eAAe,YAA0B,EAAE,CAAC,YAAY,OAAO,CAAC;AACtE,IAAM,oBAAoB,iBAA+B,YAAY;AAErE,IAAM,eAAe,YAA0B,EAAE,CAAC,OAAO,CAAC;AAC1D,IAAM,oBAAoB,iBAA+B,YAAY;","names":["props","ctx"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,14 +27,13 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "0.49.0",
31
- "@zag-js/dom-query": "0.49.0",
32
- "@zag-js/dom-event": "0.49.0",
33
- "@zag-js/element-rect": "0.49.0",
34
- "@zag-js/tabbable": "0.49.0",
35
- "@zag-js/utils": "0.49.0",
36
- "@zag-js/core": "0.49.0",
37
- "@zag-js/types": "0.49.0"
30
+ "@zag-js/anatomy": "0.50.0",
31
+ "@zag-js/dom-query": "0.50.0",
32
+ "@zag-js/dom-event": "0.50.0",
33
+ "@zag-js/element-rect": "0.50.0",
34
+ "@zag-js/utils": "0.50.0",
35
+ "@zag-js/core": "0.50.0",
36
+ "@zag-js/types": "0.50.0"
38
37
  },
39
38
  "devDependencies": {
40
39
  "clean-package": "2.2.0"
@@ -9,6 +9,11 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
9
9
  const translations = state.context.translations
10
10
  const focused = state.matches("focused")
11
11
 
12
+ const isVertical = state.context.orientation === "vertical"
13
+ const isHorizontal = state.context.orientation === "horizontal"
14
+ const composite = state.context.composite
15
+ const indicator = state.context.indicatorState
16
+
12
17
  function getTriggerState(props: TriggerProps): TriggerState {
13
18
  return {
14
19
  selected: state.context.value === props.value,
@@ -30,6 +35,20 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
30
35
  const id = dom.getTriggerId(state.context, value)
31
36
  send({ type: "SET_INDICATOR_RECT", id })
32
37
  },
38
+ syncTabIndex() {
39
+ send("SYNC_TAB_INDEX")
40
+ },
41
+ selectNext(fromValue) {
42
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectNext" })
43
+ send({ type: "ARROW_NEXT", src: "selectNext" })
44
+ },
45
+ selectPrev(fromValue) {
46
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectPrev" })
47
+ send({ type: "ARROW_PREV", src: "selectPrev" })
48
+ },
49
+ focus() {
50
+ dom.getSelectedTriggerEl(state.context)?.focus()
51
+ },
33
52
  getTriggerState,
34
53
 
35
54
  rootProps: normalize.element({
@@ -48,24 +67,30 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
48
67
  "data-focus": dataAttr(focused),
49
68
  "aria-orientation": state.context.orientation,
50
69
  "data-orientation": state.context.orientation,
51
- "aria-label": translations.listLabel,
70
+ "aria-label": translations?.listLabel,
52
71
  onKeyDown(event) {
53
72
  if (event.defaultPrevented) return
54
73
  const evt = getNativeEvent(event)
74
+
55
75
  if (!isSelfTarget(evt)) return
76
+ if (evt.isComposing) return
56
77
 
57
78
  const keyMap: EventKeyMap = {
58
79
  ArrowDown() {
59
- send("ARROW_DOWN")
80
+ if (isHorizontal) return
81
+ send({ type: "ARROW_NEXT", key: "ArrowDown" })
60
82
  },
61
83
  ArrowUp() {
62
- send("ARROW_UP")
84
+ if (isHorizontal) return
85
+ send({ type: "ARROW_PREV", key: "ArrowUp" })
63
86
  },
64
87
  ArrowLeft() {
65
- send("ARROW_LEFT")
88
+ if (isVertical) return
89
+ send({ type: "ARROW_PREV", key: "ArrowLeft" })
66
90
  },
67
91
  ArrowRight() {
68
- send("ARROW_RIGHT")
92
+ if (isVertical) return
93
+ send({ type: "ARROW_NEXT", key: "ArrowRight" })
69
94
  },
70
95
  Home() {
71
96
  send("HOME")
@@ -74,7 +99,7 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
74
99
  send("END")
75
100
  },
76
101
  Enter() {
77
- send({ type: "ENTER", value: state.context.focusedValue })
102
+ send({ type: "ENTER" })
78
103
  },
79
104
  }
80
105
 
@@ -105,10 +130,10 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
105
130
  "aria-selected": triggerState.selected,
106
131
  "data-selected": dataAttr(triggerState.selected),
107
132
  "data-focus": dataAttr(triggerState.focused),
108
- "aria-controls": dom.getContentId(state.context, value),
133
+ "aria-controls": triggerState.selected ? dom.getContentId(state.context, value) : undefined,
109
134
  "data-ownedby": dom.getListId(state.context),
110
135
  id: dom.getTriggerId(state.context, value),
111
- tabIndex: triggerState.selected ? 0 : -1,
136
+ tabIndex: triggerState.selected && composite ? 0 : -1,
112
137
  onFocus() {
113
138
  send({ type: "TAB_FOCUS", value })
114
139
  },
@@ -136,7 +161,7 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
136
161
  ...parts.content.attrs,
137
162
  dir: state.context.dir,
138
163
  id: dom.getContentId(state.context, value),
139
- tabIndex: 0,
164
+ tabIndex: composite ? 0 : -1,
140
165
  "aria-labelledby": dom.getTriggerId(state.context, value),
141
166
  role: "tabpanel",
142
167
  "data-ownedby": dom.getListId(state.context),
@@ -153,17 +178,16 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
153
178
  "data-orientation": state.context.orientation,
154
179
  style: {
155
180
  "--transition-property": "left, right, top, bottom, width, height",
156
- "--left": state.context.indicatorRect?.left,
157
- "--top": state.context.indicatorRect?.top,
158
- "--width": state.context.indicatorRect?.width,
159
- "--height": state.context.indicatorRect?.height,
181
+ "--left": indicator.rect?.left,
182
+ "--top": indicator.rect?.top,
183
+ "--width": indicator.rect?.width,
184
+ "--height": indicator.rect?.height,
160
185
  position: "absolute",
161
186
  willChange: "var(--transition-property)",
162
187
  transitionProperty: "var(--transition-property)",
163
- transitionDuration: state.context.canIndicatorTransition ? "var(--transition-duration, 150ms)" : "0ms",
188
+ transitionDuration: indicator.transition ? "var(--transition-duration, 150ms)" : "0ms",
164
189
  transitionTimingFunction: "var(--transition-timing-function)",
165
- [state.context.orientation === "horizontal" ? "left" : "top"]:
166
- state.context.orientation === "horizontal" ? "var(--left)" : "var(--top)",
190
+ [isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)",
167
191
  },
168
192
  }),
169
193
  }
package/src/tabs.dom.ts CHANGED
@@ -20,15 +20,15 @@ export const dom = createScope({
20
20
  return queryAll(dom.getListEl(ctx), selector)
21
21
  },
22
22
 
23
- getFirstEl: (ctx: Ctx) => first(dom.getElements(ctx)),
24
- getLastEl: (ctx: Ctx) => last(dom.getElements(ctx)),
25
- getNextEl: (ctx: Ctx, id: string) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
26
- getPrevEl: (ctx: Ctx, id: string) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
27
- getActiveContentEl: (ctx: Ctx) => {
23
+ getFirstTriggerEl: (ctx: Ctx) => first(dom.getElements(ctx)),
24
+ getLastTriggerEl: (ctx: Ctx) => last(dom.getElements(ctx)),
25
+ getNextTriggerEl: (ctx: Ctx, id: string) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
26
+ getPrevTriggerEl: (ctx: Ctx, id: string) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
27
+ getSelectedContentEl: (ctx: Ctx) => {
28
28
  if (!ctx.value) return
29
29
  return dom.getContentEl(ctx, ctx.value)
30
30
  },
31
- getActiveTabEl: (ctx: Ctx) => {
31
+ getSelectedTriggerEl: (ctx: Ctx) => {
32
32
  if (!ctx.value) return
33
33
  return dom.getTriggerEl(ctx, ctx.value)
34
34
  },
@@ -1,8 +1,7 @@
1
1
  import { createMachine, guards } from "@zag-js/core"
2
2
  import { clickIfLink } from "@zag-js/dom-event"
3
- import { nextTick, raf } from "@zag-js/dom-query"
3
+ import { nextTick, raf, getFocusables } from "@zag-js/dom-query"
4
4
  import { trackElementRect } from "@zag-js/element-rect"
5
- import { getFocusables } from "@zag-js/tabbable"
6
5
  import { compact, isEqual } from "@zag-js/utils"
7
6
  import { dom } from "./tabs.dom"
8
7
  import type { MachineContext, MachineState, UserDefinedContext } from "./tabs.types"
@@ -20,31 +19,19 @@ export function machine(userContext: UserDefinedContext) {
20
19
  orientation: "horizontal",
21
20
  activationMode: "automatic",
22
21
  value: null,
23
- focusedValue: null,
24
- indicatorRect: {
25
- left: "0px",
26
- top: "0px",
27
- width: "0px",
28
- height: "0px",
29
- },
30
- canIndicatorTransition: false,
31
- isIndicatorRendered: false,
32
22
  loopFocus: true,
33
- translations: {},
23
+ composite: true,
34
24
  ...ctx,
25
+ focusedValue: ctx.value ?? null,
26
+ indicatorState: {
27
+ rendered: false,
28
+ transition: false,
29
+ rect: { left: "0px", top: "0px", width: "0px", height: "0px" },
30
+ },
35
31
  },
36
32
 
37
- computed: {
38
- isHorizontal: (ctx) => ctx.orientation === "horizontal",
39
- isVertical: (ctx) => ctx.orientation === "vertical",
40
- },
41
-
42
- entry: ["checkRenderedElements", "syncIndicatorRect", "setContentTabIndex"],
43
-
44
- exit: ["cleanupObserver"],
45
-
46
33
  watch: {
47
- value: ["enableIndicatorTransition", "syncIndicatorRect", "setContentTabIndex", "clickIfLink"],
34
+ value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "clickIfLink"],
48
35
  dir: ["syncIndicatorRect"],
49
36
  orientation: ["syncIndicatorRect"],
50
37
  },
@@ -59,22 +46,22 @@ export function machine(userContext: UserDefinedContext) {
59
46
  SET_INDICATOR_RECT: {
60
47
  actions: "setIndicatorRect",
61
48
  },
49
+ SYNC_TAB_INDEX: {
50
+ actions: "syncTabIndex",
51
+ },
62
52
  },
63
53
 
54
+ created: ["syncFocusedValue"],
55
+ entry: ["checkRenderedElements", "syncIndicatorRect", "syncTabIndex"],
56
+ exit: ["cleanupObserver"],
57
+
64
58
  states: {
65
59
  idle: {
66
60
  on: {
67
- TAB_FOCUS: [
68
- {
69
- guard: "selectOnFocus",
70
- target: "focused",
71
- actions: ["setFocusedValue", "setValue"],
72
- },
73
- {
74
- target: "focused",
75
- actions: "setFocusedValue",
76
- },
77
- ],
61
+ TAB_FOCUS: {
62
+ target: "focused",
63
+ actions: "setFocusedValue",
64
+ },
78
65
  TAB_CLICK: {
79
66
  target: "focused",
80
67
  actions: ["setFocusedValue", "setValue"],
@@ -87,39 +74,49 @@ export function machine(userContext: UserDefinedContext) {
87
74
  target: "focused",
88
75
  actions: ["setFocusedValue", "setValue"],
89
76
  },
90
- ARROW_LEFT: {
91
- guard: "isHorizontal",
92
- actions: "focusPrevTab",
93
- },
94
- ARROW_RIGHT: {
95
- guard: "isHorizontal",
96
- actions: "focusNextTab",
97
- },
98
- ARROW_UP: {
99
- guard: "isVertical",
100
- actions: "focusPrevTab",
101
- },
102
- ARROW_DOWN: {
103
- guard: "isVertical",
104
- actions: "focusNextTab",
105
- },
106
- HOME: {
107
- actions: "focusFirstTab",
108
- },
109
- END: {
110
- actions: "focusLastTab",
111
- },
112
- ENTER: {
113
- guard: not("selectOnFocus"),
114
- actions: "setValue",
115
- },
116
- TAB_FOCUS: [
77
+ ARROW_PREV: [
78
+ {
79
+ guard: "selectOnFocus",
80
+ actions: ["focusPrevTab", "selectFocusedTab"],
81
+ },
82
+ {
83
+ actions: "focusPrevTab",
84
+ },
85
+ ],
86
+ ARROW_NEXT: [
117
87
  {
118
88
  guard: "selectOnFocus",
119
- actions: ["setFocusedValue", "setValue"],
89
+ actions: ["focusNextTab", "selectFocusedTab"],
90
+ },
91
+ {
92
+ actions: "focusNextTab",
93
+ },
94
+ ],
95
+ HOME: [
96
+ {
97
+ guard: "selectOnFocus",
98
+ actions: ["focusFirstTab", "selectFocusedTab"],
99
+ },
100
+ {
101
+ actions: "focusFirstTab",
120
102
  },
121
- { actions: "setFocusedValue" },
122
103
  ],
104
+ END: [
105
+ {
106
+ guard: "selectOnFocus",
107
+ actions: ["focusLastTab", "selectFocusedTab"],
108
+ },
109
+ {
110
+ actions: "focusLastTab",
111
+ },
112
+ ],
113
+ ENTER: {
114
+ guard: not("selectOnFocus"),
115
+ actions: "selectFocusedTab",
116
+ },
117
+ TAB_FOCUS: {
118
+ actions: ["setFocusedValue"],
119
+ },
123
120
  TAB_BLUR: {
124
121
  target: "idle",
125
122
  actions: "clearFocusedValue",
@@ -130,13 +127,22 @@ export function machine(userContext: UserDefinedContext) {
130
127
  },
131
128
  {
132
129
  guards: {
133
- isVertical: (ctx) => ctx.isVertical,
134
- isHorizontal: (ctx) => ctx.isHorizontal,
135
130
  selectOnFocus: (ctx) => ctx.activationMode === "automatic",
136
131
  },
137
132
 
138
133
  actions: {
134
+ syncFocusedValue(ctx) {
135
+ if (ctx.value != null && ctx.focusedValue == null) {
136
+ ctx.focusedValue = ctx.value
137
+ }
138
+ },
139
+ selectFocusedTab(ctx) {
140
+ raf(() => {
141
+ set.value(ctx, ctx.focusedValue)
142
+ })
143
+ },
139
144
  setFocusedValue(ctx, evt) {
145
+ if (evt.value == null) return
140
146
  set.focusedValue(ctx, evt.value)
141
147
  },
142
148
  clearFocusedValue(ctx) {
@@ -149,78 +155,93 @@ export function machine(userContext: UserDefinedContext) {
149
155
  set.value(ctx, null)
150
156
  },
151
157
  focusFirstTab(ctx) {
152
- raf(() => dom.getFirstEl(ctx)?.focus())
158
+ raf(() => {
159
+ dom.getFirstTriggerEl(ctx)?.focus()
160
+ })
153
161
  },
154
162
  focusLastTab(ctx) {
155
- raf(() => dom.getLastEl(ctx)?.focus())
163
+ raf(() => {
164
+ dom.getLastTriggerEl(ctx)?.focus()
165
+ })
156
166
  },
157
167
  focusNextTab(ctx) {
158
168
  if (!ctx.focusedValue) return
159
- const next = dom.getNextEl(ctx, ctx.focusedValue)
160
- raf(() => next?.focus())
169
+ const triggerEl = dom.getNextTriggerEl(ctx, ctx.focusedValue)
170
+ raf(() => {
171
+ if (ctx.composite) {
172
+ triggerEl?.focus()
173
+ } else if (triggerEl?.dataset.value != null) {
174
+ set.focusedValue(ctx, triggerEl.dataset.value)
175
+ }
176
+ })
161
177
  },
162
178
  focusPrevTab(ctx) {
163
179
  if (!ctx.focusedValue) return
164
- const prev = dom.getPrevEl(ctx, ctx.focusedValue)
165
- raf(() => prev?.focus())
180
+ const triggerEl = dom.getPrevTriggerEl(ctx, ctx.focusedValue)
181
+ raf(() => {
182
+ if (ctx.composite) {
183
+ triggerEl?.focus()
184
+ } else if (triggerEl?.dataset.value != null) {
185
+ set.focusedValue(ctx, triggerEl.dataset.value)
186
+ }
187
+ })
166
188
  },
167
189
  checkRenderedElements(ctx) {
168
- ctx.isIndicatorRendered = !!dom.getIndicatorEl(ctx)
190
+ ctx.indicatorState.rendered = !!dom.getIndicatorEl(ctx)
169
191
  },
170
- // if tab panel contains focusable elements, remove the tabindex attribute
171
- setContentTabIndex(ctx) {
192
+ syncTabIndex(ctx) {
172
193
  raf(() => {
173
- const panel = dom.getActiveContentEl(ctx)
174
- if (!panel) return
175
- const focusables = getFocusables(panel)
194
+ const contentEl = dom.getSelectedContentEl(ctx)
195
+ if (!contentEl) return
196
+ const focusables = getFocusables(contentEl)
176
197
  if (focusables.length > 0) {
177
- panel.removeAttribute("tabindex")
198
+ contentEl.removeAttribute("tabindex")
178
199
  } else {
179
- panel.setAttribute("tabindex", "0")
200
+ contentEl.setAttribute("tabindex", "0")
180
201
  }
181
202
  })
182
203
  },
183
204
  cleanupObserver(ctx) {
184
205
  ctx.indicatorCleanup?.()
185
206
  },
186
- enableIndicatorTransition(ctx) {
187
- ctx.canIndicatorTransition = true
207
+ allowIndicatorTransition(ctx) {
208
+ ctx.indicatorState.transition = true
188
209
  },
189
210
  setIndicatorRect(ctx, evt) {
190
211
  const value = evt.id ?? ctx.value
191
- if (!ctx.isIndicatorRendered || !value) return
212
+ if (!ctx.indicatorState.rendered || !value) return
192
213
 
193
- const tabEl = dom.getTriggerEl(ctx, value)
194
- if (!tabEl) return
214
+ const triggerEl = dom.getTriggerEl(ctx, value)
215
+ if (!triggerEl) return
195
216
 
196
- ctx.indicatorRect = dom.getRectById(ctx, value)
217
+ ctx.indicatorState.rect = dom.getRectById(ctx, value)
197
218
  nextTick(() => {
198
- ctx.canIndicatorTransition = false
219
+ ctx.indicatorState.transition = false
199
220
  })
200
221
  },
201
222
  syncIndicatorRect(ctx) {
202
223
  ctx.indicatorCleanup?.()
203
224
 
204
225
  const value = ctx.value
205
- if (!ctx.isIndicatorRendered || !value) return
226
+ if (!ctx.indicatorState.rendered || !value) return
206
227
 
207
- const tabEl = dom.getActiveTabEl(ctx)
208
- if (!tabEl) return
228
+ const triggerEl = dom.getSelectedTriggerEl(ctx)
229
+ if (!triggerEl) return
209
230
 
210
- ctx.indicatorCleanup = trackElementRect(tabEl, {
231
+ ctx.indicatorCleanup = trackElementRect(triggerEl, {
211
232
  getRect(el) {
212
233
  return dom.getOffsetRect(el)
213
234
  },
214
235
  onChange(rect) {
215
- ctx.indicatorRect = dom.resolveRect(rect)
236
+ ctx.indicatorState.rect = dom.resolveRect(rect)
216
237
  nextTick(() => {
217
- ctx.canIndicatorTransition = false
238
+ ctx.indicatorState.transition = false
218
239
  })
219
240
  },
220
241
  })
221
242
  },
222
243
  clickIfLink(ctx) {
223
- clickIfLink(dom.getActiveTabEl(ctx))
244
+ clickIfLink(dom.getSelectedTriggerEl(ctx))
224
245
  },
225
246
  },
226
247
  },
package/src/tabs.props.ts CHANGED
@@ -4,6 +4,7 @@ import type { ContentProps, TriggerProps, UserDefinedContext } from "./tabs.type
4
4
 
5
5
  export const props = createProps<UserDefinedContext>()([
6
6
  "activationMode",
7
+ "composite",
7
8
  "dir",
8
9
  "getRootNode",
9
10
  "id",