@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.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/tabs.anatomy.ts","../src/tabs.connect.ts","../src/tabs.dom.ts","../src/tabs.machine.ts","../src/tabs.props.ts"],"sourcesContent":["export { anatomy } from \"./tabs.anatomy\"\nexport { connect } from \"./tabs.connect\"\nexport { machine } from \"./tabs.machine\"\nexport * from \"./tabs.props\"\nexport type {\n MachineApi as Api,\n ContentProps,\n UserDefinedContext as Context,\n ElementIds,\n FocusChangeDetails,\n IntlTranslations,\n TriggerProps,\n ValueChangeDetails,\n} from \"./tabs.types\"\n","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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA8B;AAEvB,IAAM,cAAU,8BAAc,MAAM,EAAE,MAAM,QAAQ,QAAQ,WAAW,WAAW,WAAW;AAC7F,IAAM,QAAQ,QAAQ,MAAM;;;ACHnC,uBAA8D;AAC9D,IAAAA,oBAAiD;;;ACDjD,uBAAoE;AACpE,mBAA4B;AAGrB,IAAM,UAAM,8BAAY;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,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C1D,IAAM,wBAAoB,gCAA+B,YAAY;","names":["import_dom_query","props","import_dom_event","import_dom_query","import_utils","ctx","import_utils"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/tabs.anatomy.ts","../src/tabs.connect.ts","../src/tabs.dom.ts","../src/tabs.machine.ts","../src/tabs.props.ts"],"sourcesContent":["export { anatomy } from \"./tabs.anatomy\"\nexport { connect } from \"./tabs.connect\"\nexport { machine } from \"./tabs.machine\"\nexport * from \"./tabs.props\"\nexport type {\n MachineApi as Api,\n ContentProps,\n UserDefinedContext as Context,\n ElementIds,\n FocusChangeDetails,\n IntlTranslations,\n TriggerProps,\n ValueChangeDetails,\n} from \"./tabs.types\"\n","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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA8B;AAEvB,IAAM,cAAU,8BA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C,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,YAAI,uBAAQ,OAAO,IAAI,KAAK;AAAG;AAC/B,QAAI,QAAQ;AACZ,WAAO,OAAO,GAAG;AAAA,EACnB;AAAA,EACA,cAAc,CAAC,KAAqB,UAAyB;AAC3D,YAAI,uBAAQ,OAAO,IAAI,YAAY;AAAG;AACtC,QAAI,eAAe;AACnB,WAAO,YAAY,GAAG;AAAA,EACxB;AACF;;;AChRA,mBAA4B;AAC5B,IAAAC,gBAAiC;AAG1B,IAAM,YAAQ,0BAAgC,EAAE;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,iBAAa,gCAA8C,KAAK;AAEtE,IAAM,mBAAe,0BAA0B,EAAE,CAAC,YAAY,OAAO,CAAC;AACtE,IAAM,wBAAoB,gCAA+B,YAAY;AAErE,IAAM,mBAAe,0BAA0B,EAAE,CAAC,OAAO,CAAC;AAC1D,IAAM,wBAAoB,gCAA+B,YAAY;","names":["import_dom_query","props","import_dom_event","import_dom_query","import_utils","ctx","import_utils"]}
package/dist/index.mjs CHANGED
@@ -25,16 +25,16 @@ var dom = createScope({
25
25
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
26
26
  return queryAll(dom.getListEl(ctx), selector);
27
27
  },
28
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
29
- getLastEl: (ctx) => last(dom.getElements(ctx)),
30
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
31
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
32
- getActiveContentEl: (ctx) => {
28
+ getFirstTriggerEl: (ctx) => first(dom.getElements(ctx)),
29
+ getLastTriggerEl: (ctx) => last(dom.getElements(ctx)),
30
+ getNextTriggerEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
31
+ getPrevTriggerEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
32
+ getSelectedContentEl: (ctx) => {
33
33
  if (!ctx.value)
34
34
  return;
35
35
  return dom.getContentEl(ctx, ctx.value);
36
36
  },
37
- getActiveTabEl: (ctx) => {
37
+ getSelectedTriggerEl: (ctx) => {
38
38
  if (!ctx.value)
39
39
  return;
40
40
  return dom.getTriggerEl(ctx, ctx.value);
@@ -63,6 +63,10 @@ var dom = createScope({
63
63
  function connect(state, send, normalize) {
64
64
  const translations = state.context.translations;
65
65
  const focused = state.matches("focused");
66
+ const isVertical = state.context.orientation === "vertical";
67
+ const isHorizontal = state.context.orientation === "horizontal";
68
+ const composite = state.context.composite;
69
+ const indicator = state.context.indicatorState;
66
70
  function getTriggerState(props2) {
67
71
  return {
68
72
  selected: state.context.value === props2.value,
@@ -83,6 +87,20 @@ function connect(state, send, normalize) {
83
87
  const id = dom.getTriggerId(state.context, value);
84
88
  send({ type: "SET_INDICATOR_RECT", id });
85
89
  },
90
+ syncTabIndex() {
91
+ send("SYNC_TAB_INDEX");
92
+ },
93
+ selectNext(fromValue) {
94
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectNext" });
95
+ send({ type: "ARROW_NEXT", src: "selectNext" });
96
+ },
97
+ selectPrev(fromValue) {
98
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectPrev" });
99
+ send({ type: "ARROW_PREV", src: "selectPrev" });
100
+ },
101
+ focus() {
102
+ dom.getSelectedTriggerEl(state.context)?.focus();
103
+ },
86
104
  getTriggerState,
87
105
  rootProps: normalize.element({
88
106
  ...parts.root.attrs,
@@ -99,25 +117,35 @@ function connect(state, send, normalize) {
99
117
  "data-focus": dataAttr(focused),
100
118
  "aria-orientation": state.context.orientation,
101
119
  "data-orientation": state.context.orientation,
102
- "aria-label": translations.listLabel,
120
+ "aria-label": translations?.listLabel,
103
121
  onKeyDown(event) {
104
122
  if (event.defaultPrevented)
105
123
  return;
106
124
  const evt = getNativeEvent(event);
107
125
  if (!isSelfTarget(evt))
108
126
  return;
127
+ if (evt.isComposing)
128
+ return;
109
129
  const keyMap = {
110
130
  ArrowDown() {
111
- send("ARROW_DOWN");
131
+ if (isHorizontal)
132
+ return;
133
+ send({ type: "ARROW_NEXT", key: "ArrowDown" });
112
134
  },
113
135
  ArrowUp() {
114
- send("ARROW_UP");
136
+ if (isHorizontal)
137
+ return;
138
+ send({ type: "ARROW_PREV", key: "ArrowUp" });
115
139
  },
116
140
  ArrowLeft() {
117
- send("ARROW_LEFT");
141
+ if (isVertical)
142
+ return;
143
+ send({ type: "ARROW_PREV", key: "ArrowLeft" });
118
144
  },
119
145
  ArrowRight() {
120
- send("ARROW_RIGHT");
146
+ if (isVertical)
147
+ return;
148
+ send({ type: "ARROW_NEXT", key: "ArrowRight" });
121
149
  },
122
150
  Home() {
123
151
  send("HOME");
@@ -126,7 +154,7 @@ function connect(state, send, normalize) {
126
154
  send("END");
127
155
  },
128
156
  Enter() {
129
- send({ type: "ENTER", value: state.context.focusedValue });
157
+ send({ type: "ENTER" });
130
158
  }
131
159
  };
132
160
  let key = getEventKey(event, state.context);
@@ -153,10 +181,10 @@ function connect(state, send, normalize) {
153
181
  "aria-selected": triggerState.selected,
154
182
  "data-selected": dataAttr(triggerState.selected),
155
183
  "data-focus": dataAttr(triggerState.focused),
156
- "aria-controls": dom.getContentId(state.context, value),
184
+ "aria-controls": triggerState.selected ? dom.getContentId(state.context, value) : void 0,
157
185
  "data-ownedby": dom.getListId(state.context),
158
186
  id: dom.getTriggerId(state.context, value),
159
- tabIndex: triggerState.selected ? 0 : -1,
187
+ tabIndex: triggerState.selected && composite ? 0 : -1,
160
188
  onFocus() {
161
189
  send({ type: "TAB_FOCUS", value });
162
190
  },
@@ -185,7 +213,7 @@ function connect(state, send, normalize) {
185
213
  ...parts.content.attrs,
186
214
  dir: state.context.dir,
187
215
  id: dom.getContentId(state.context, value),
188
- tabIndex: 0,
216
+ tabIndex: composite ? 0 : -1,
189
217
  "aria-labelledby": dom.getTriggerId(state.context, value),
190
218
  role: "tabpanel",
191
219
  "data-ownedby": dom.getListId(state.context),
@@ -201,16 +229,16 @@ function connect(state, send, normalize) {
201
229
  "data-orientation": state.context.orientation,
202
230
  style: {
203
231
  "--transition-property": "left, right, top, bottom, width, height",
204
- "--left": state.context.indicatorRect?.left,
205
- "--top": state.context.indicatorRect?.top,
206
- "--width": state.context.indicatorRect?.width,
207
- "--height": state.context.indicatorRect?.height,
232
+ "--left": indicator.rect?.left,
233
+ "--top": indicator.rect?.top,
234
+ "--width": indicator.rect?.width,
235
+ "--height": indicator.rect?.height,
208
236
  position: "absolute",
209
237
  willChange: "var(--transition-property)",
210
238
  transitionProperty: "var(--transition-property)",
211
- transitionDuration: state.context.canIndicatorTransition ? "var(--transition-duration, 150ms)" : "0ms",
239
+ transitionDuration: indicator.transition ? "var(--transition-duration, 150ms)" : "0ms",
212
240
  transitionTimingFunction: "var(--transition-timing-function)",
213
- [state.context.orientation === "horizontal" ? "left" : "top"]: state.context.orientation === "horizontal" ? "var(--left)" : "var(--top)"
241
+ [isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
214
242
  }
215
243
  })
216
244
  };
@@ -219,9 +247,8 @@ function connect(state, send, normalize) {
219
247
  // src/tabs.machine.ts
220
248
  import { createMachine, guards } from "@zag-js/core";
221
249
  import { clickIfLink } from "@zag-js/dom-event";
222
- import { nextTick, raf } from "@zag-js/dom-query";
250
+ import { nextTick, raf, getFocusables } from "@zag-js/dom-query";
223
251
  import { trackElementRect } from "@zag-js/element-rect";
224
- import { getFocusables } from "@zag-js/tabbable";
225
252
  import { compact, isEqual } from "@zag-js/utils";
226
253
  var { not } = guards;
227
254
  function machine(userContext) {
@@ -234,27 +261,18 @@ function machine(userContext) {
234
261
  orientation: "horizontal",
235
262
  activationMode: "automatic",
236
263
  value: null,
237
- focusedValue: null,
238
- indicatorRect: {
239
- left: "0px",
240
- top: "0px",
241
- width: "0px",
242
- height: "0px"
243
- },
244
- canIndicatorTransition: false,
245
- isIndicatorRendered: false,
246
264
  loopFocus: true,
247
- translations: {},
248
- ...ctx
249
- },
250
- computed: {
251
- isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
252
- isVertical: (ctx2) => ctx2.orientation === "vertical"
265
+ composite: true,
266
+ ...ctx,
267
+ focusedValue: ctx.value ?? null,
268
+ indicatorState: {
269
+ rendered: false,
270
+ transition: false,
271
+ rect: { left: "0px", top: "0px", width: "0px", height: "0px" }
272
+ }
253
273
  },
254
- entry: ["checkRenderedElements", "syncIndicatorRect", "setContentTabIndex"],
255
- exit: ["cleanupObserver"],
256
274
  watch: {
257
- value: ["enableIndicatorTransition", "syncIndicatorRect", "setContentTabIndex", "clickIfLink"],
275
+ value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "clickIfLink"],
258
276
  dir: ["syncIndicatorRect"],
259
277
  orientation: ["syncIndicatorRect"]
260
278
  },
@@ -267,22 +285,21 @@ function machine(userContext) {
267
285
  },
268
286
  SET_INDICATOR_RECT: {
269
287
  actions: "setIndicatorRect"
288
+ },
289
+ SYNC_TAB_INDEX: {
290
+ actions: "syncTabIndex"
270
291
  }
271
292
  },
293
+ created: ["syncFocusedValue"],
294
+ entry: ["checkRenderedElements", "syncIndicatorRect", "syncTabIndex"],
295
+ exit: ["cleanupObserver"],
272
296
  states: {
273
297
  idle: {
274
298
  on: {
275
- TAB_FOCUS: [
276
- {
277
- guard: "selectOnFocus",
278
- target: "focused",
279
- actions: ["setFocusedValue", "setValue"]
280
- },
281
- {
282
- target: "focused",
283
- actions: "setFocusedValue"
284
- }
285
- ],
299
+ TAB_FOCUS: {
300
+ target: "focused",
301
+ actions: "setFocusedValue"
302
+ },
286
303
  TAB_CLICK: {
287
304
  target: "focused",
288
305
  actions: ["setFocusedValue", "setValue"]
@@ -295,39 +312,49 @@ function machine(userContext) {
295
312
  target: "focused",
296
313
  actions: ["setFocusedValue", "setValue"]
297
314
  },
298
- ARROW_LEFT: {
299
- guard: "isHorizontal",
300
- actions: "focusPrevTab"
301
- },
302
- ARROW_RIGHT: {
303
- guard: "isHorizontal",
304
- actions: "focusNextTab"
305
- },
306
- ARROW_UP: {
307
- guard: "isVertical",
308
- actions: "focusPrevTab"
309
- },
310
- ARROW_DOWN: {
311
- guard: "isVertical",
312
- actions: "focusNextTab"
313
- },
314
- HOME: {
315
- actions: "focusFirstTab"
316
- },
317
- END: {
318
- actions: "focusLastTab"
319
- },
320
- ENTER: {
321
- guard: not("selectOnFocus"),
322
- actions: "setValue"
323
- },
324
- TAB_FOCUS: [
315
+ ARROW_PREV: [
316
+ {
317
+ guard: "selectOnFocus",
318
+ actions: ["focusPrevTab", "selectFocusedTab"]
319
+ },
320
+ {
321
+ actions: "focusPrevTab"
322
+ }
323
+ ],
324
+ ARROW_NEXT: [
325
+ {
326
+ guard: "selectOnFocus",
327
+ actions: ["focusNextTab", "selectFocusedTab"]
328
+ },
329
+ {
330
+ actions: "focusNextTab"
331
+ }
332
+ ],
333
+ HOME: [
334
+ {
335
+ guard: "selectOnFocus",
336
+ actions: ["focusFirstTab", "selectFocusedTab"]
337
+ },
338
+ {
339
+ actions: "focusFirstTab"
340
+ }
341
+ ],
342
+ END: [
325
343
  {
326
344
  guard: "selectOnFocus",
327
- actions: ["setFocusedValue", "setValue"]
345
+ actions: ["focusLastTab", "selectFocusedTab"]
328
346
  },
329
- { actions: "setFocusedValue" }
347
+ {
348
+ actions: "focusLastTab"
349
+ }
330
350
  ],
351
+ ENTER: {
352
+ guard: not("selectOnFocus"),
353
+ actions: "selectFocusedTab"
354
+ },
355
+ TAB_FOCUS: {
356
+ actions: ["setFocusedValue"]
357
+ },
331
358
  TAB_BLUR: {
332
359
  target: "idle",
333
360
  actions: "clearFocusedValue"
@@ -338,12 +365,22 @@ function machine(userContext) {
338
365
  },
339
366
  {
340
367
  guards: {
341
- isVertical: (ctx2) => ctx2.isVertical,
342
- isHorizontal: (ctx2) => ctx2.isHorizontal,
343
368
  selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
344
369
  },
345
370
  actions: {
371
+ syncFocusedValue(ctx2) {
372
+ if (ctx2.value != null && ctx2.focusedValue == null) {
373
+ ctx2.focusedValue = ctx2.value;
374
+ }
375
+ },
376
+ selectFocusedTab(ctx2) {
377
+ raf(() => {
378
+ set.value(ctx2, ctx2.focusedValue);
379
+ });
380
+ },
346
381
  setFocusedValue(ctx2, evt) {
382
+ if (evt.value == null)
383
+ return;
347
384
  set.focusedValue(ctx2, evt.value);
348
385
  },
349
386
  clearFocusedValue(ctx2) {
@@ -356,80 +393,95 @@ function machine(userContext) {
356
393
  set.value(ctx2, null);
357
394
  },
358
395
  focusFirstTab(ctx2) {
359
- raf(() => dom.getFirstEl(ctx2)?.focus());
396
+ raf(() => {
397
+ dom.getFirstTriggerEl(ctx2)?.focus();
398
+ });
360
399
  },
361
400
  focusLastTab(ctx2) {
362
- raf(() => dom.getLastEl(ctx2)?.focus());
401
+ raf(() => {
402
+ dom.getLastTriggerEl(ctx2)?.focus();
403
+ });
363
404
  },
364
405
  focusNextTab(ctx2) {
365
406
  if (!ctx2.focusedValue)
366
407
  return;
367
- const next = dom.getNextEl(ctx2, ctx2.focusedValue);
368
- raf(() => next?.focus());
408
+ const triggerEl = dom.getNextTriggerEl(ctx2, ctx2.focusedValue);
409
+ raf(() => {
410
+ if (ctx2.composite) {
411
+ triggerEl?.focus();
412
+ } else if (triggerEl?.dataset.value != null) {
413
+ set.focusedValue(ctx2, triggerEl.dataset.value);
414
+ }
415
+ });
369
416
  },
370
417
  focusPrevTab(ctx2) {
371
418
  if (!ctx2.focusedValue)
372
419
  return;
373
- const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
374
- raf(() => prev?.focus());
420
+ const triggerEl = dom.getPrevTriggerEl(ctx2, ctx2.focusedValue);
421
+ raf(() => {
422
+ if (ctx2.composite) {
423
+ triggerEl?.focus();
424
+ } else if (triggerEl?.dataset.value != null) {
425
+ set.focusedValue(ctx2, triggerEl.dataset.value);
426
+ }
427
+ });
375
428
  },
376
429
  checkRenderedElements(ctx2) {
377
- ctx2.isIndicatorRendered = !!dom.getIndicatorEl(ctx2);
430
+ ctx2.indicatorState.rendered = !!dom.getIndicatorEl(ctx2);
378
431
  },
379
- // if tab panel contains focusable elements, remove the tabindex attribute
380
- setContentTabIndex(ctx2) {
432
+ syncTabIndex(ctx2) {
381
433
  raf(() => {
382
- const panel = dom.getActiveContentEl(ctx2);
383
- if (!panel)
434
+ const contentEl = dom.getSelectedContentEl(ctx2);
435
+ if (!contentEl)
384
436
  return;
385
- const focusables = getFocusables(panel);
437
+ const focusables = getFocusables(contentEl);
386
438
  if (focusables.length > 0) {
387
- panel.removeAttribute("tabindex");
439
+ contentEl.removeAttribute("tabindex");
388
440
  } else {
389
- panel.setAttribute("tabindex", "0");
441
+ contentEl.setAttribute("tabindex", "0");
390
442
  }
391
443
  });
392
444
  },
393
445
  cleanupObserver(ctx2) {
394
446
  ctx2.indicatorCleanup?.();
395
447
  },
396
- enableIndicatorTransition(ctx2) {
397
- ctx2.canIndicatorTransition = true;
448
+ allowIndicatorTransition(ctx2) {
449
+ ctx2.indicatorState.transition = true;
398
450
  },
399
451
  setIndicatorRect(ctx2, evt) {
400
452
  const value = evt.id ?? ctx2.value;
401
- if (!ctx2.isIndicatorRendered || !value)
453
+ if (!ctx2.indicatorState.rendered || !value)
402
454
  return;
403
- const tabEl = dom.getTriggerEl(ctx2, value);
404
- if (!tabEl)
455
+ const triggerEl = dom.getTriggerEl(ctx2, value);
456
+ if (!triggerEl)
405
457
  return;
406
- ctx2.indicatorRect = dom.getRectById(ctx2, value);
458
+ ctx2.indicatorState.rect = dom.getRectById(ctx2, value);
407
459
  nextTick(() => {
408
- ctx2.canIndicatorTransition = false;
460
+ ctx2.indicatorState.transition = false;
409
461
  });
410
462
  },
411
463
  syncIndicatorRect(ctx2) {
412
464
  ctx2.indicatorCleanup?.();
413
465
  const value = ctx2.value;
414
- if (!ctx2.isIndicatorRendered || !value)
466
+ if (!ctx2.indicatorState.rendered || !value)
415
467
  return;
416
- const tabEl = dom.getActiveTabEl(ctx2);
417
- if (!tabEl)
468
+ const triggerEl = dom.getSelectedTriggerEl(ctx2);
469
+ if (!triggerEl)
418
470
  return;
419
- ctx2.indicatorCleanup = trackElementRect(tabEl, {
471
+ ctx2.indicatorCleanup = trackElementRect(triggerEl, {
420
472
  getRect(el) {
421
473
  return dom.getOffsetRect(el);
422
474
  },
423
475
  onChange(rect) {
424
- ctx2.indicatorRect = dom.resolveRect(rect);
476
+ ctx2.indicatorState.rect = dom.resolveRect(rect);
425
477
  nextTick(() => {
426
- ctx2.canIndicatorTransition = false;
478
+ ctx2.indicatorState.transition = false;
427
479
  });
428
480
  }
429
481
  });
430
482
  },
431
483
  clickIfLink(ctx2) {
432
- clickIfLink(dom.getActiveTabEl(ctx2));
484
+ clickIfLink(dom.getSelectedTriggerEl(ctx2));
433
485
  }
434
486
  }
435
487
  }
@@ -467,6 +519,7 @@ import { createProps } from "@zag-js/types";
467
519
  import { createSplitProps } from "@zag-js/utils";
468
520
  var props = createProps()([
469
521
  "activationMode",
522
+ "composite",
470
523
  "dir",
471
524
  "getRootNode",
472
525
  "id",