Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radix-ui/react-menu

Package Overview
Dependencies
Maintainers
5
Versions
262
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-menu - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

2

dist/index.js

@@ -1,2 +0,2 @@

var e=require("aria-hidden").hideOthers,r=require("react-remove-scroll").RemoveScroll,t=require("@radix-ui/react-focus-guards").useFocusGuards,n=require("@radix-ui/react-portal").Portal,o=require("@radix-ui/react-focus-scope").FocusScope,a=require("@radix-ui/react-dismissable-layer").DismissableLayer,u=O({},require("@radix-ui/react-popper")),i=require("@radix-ui/react-roving-focus"),c=i.RovingFocusGroup,l=i.useRovingFocus,s=require("@radix-ui/react-primitive"),f=s.Primitive,d=s.extendPrimitive,p=require("@radix-ui/react-presence").Presence,v=require("@radix-ui/react-use-callback-ref").useCallbackRef,m=require("@radix-ui/react-context").createContext,y=require("@radix-ui/react-compose-refs"),b=y.composeRefs,h=y.useComposedRefs,w=require("@radix-ui/primitive").composeEventHandlers,x=O({},require("react"));function O(e,r){return Object.keys(r).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})})),e}function g(){var e=x.useRef(0),r=x.useRef(""),t=x.useCallback((function(n){r.current=n,window.clearTimeout(e.current),e.current=window.setTimeout((function(){return t("")}),1e3)}),[]);return{onKeyDownCapture:function(e){if(1===e.key.length&&!(e.ctrlKey||e.altKey||e.metaKey)){var n=e.currentTarget;t(r.current+e.key)," "!==e.key||r.current.startsWith(" ")||e.stopPropagation();var o=document.activeElement,a=o?C(o):void 0,u=function(e,r,t){var n=r.length>1&&Array.from(r).every((function(e){return e===r[0]}))?r[0]:r,o=t?e.indexOf(t):-1,a=(u=e,i=Math.max(o,0),u.map((function(e,r){return u[(i+r)%u.length]})));var u,i;1===n.length&&(a=a.filter((function(e){return e!==t})));var c=a.find((function(e){return e.toLowerCase().startsWith(n.toLowerCase())}));return c!==t?c:void 0}(Array.from(n.querySelectorAll("[".concat(M,"]"))).map(C),r.current,a),i=n.querySelector("[".concat(M,'="').concat(u,'"]'));i&&setTimeout((function(){return i.focus()}))}}}}var C=function(e){var r;return null!==(r=e.getAttribute(M))&&void 0!==r?r:""},M="data-radix-menu-typeahead-item";function D(e){var r,t,n,o=e.textValue,a=e.disabled;return n=a?void 0:o,(t=M)in(r={})?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r}function P(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function E(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?P(Object(t),!0).forEach((function(r){S(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):P(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function S(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function k(){return(k=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function R(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t=a[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)t=a[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function F(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var t=[],n=!0,o=!1,a=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done)&&(t.push(u.value),!r||t.length!==r);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return t}(e,r)||function(e,r){if(!e)return;if("string"==typeof e)return I(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return I(e,r)}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}var j=["ArrowDown","PageUp","Home"],A=[].concat(j,["ArrowUp","PageDown","End"]),q=F(m("Menu"),2),K=q[0],L=q[1],N=x.forwardRef((function(e,r){var t=e.forceMount,n=e.open,o=void 0!==n&&n,a=R(e,["forceMount","open"]);return x.createElement(p,{present:t||o},x.createElement(T,k({"data-state":Y(o)},a,{ref:r,open:o})))}));exports.Menu=N;var T=x.forwardRef((function(i,l){var s=i.open,f=i.onOpenChange,d=i.anchorRef,p=i.loop,m=i.trapFocus,y=i.onOpenAutoFocus,h=i.onCloseAutoFocus,O=i.disableOutsidePointerEvents,C=i.onEscapeKeyDown,M=i.onPointerDownOutside,D=i.onFocusOutside,P=i.onInteractOutside,S=i.onDismiss,I=i.disableOutsideScroll,q=i.portalled,L=R(i,["open","onOpenChange","anchorRef","loop","trapFocus","onOpenAutoFocus","onCloseAutoFocus","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","disableOutsideScroll","portalled"]),N=v(f),T=x.useRef(null),V=F(x.useState(0),2),U=V[0],B=V[1],H=F(x.useState(!1),2),W=H[0],_=H[1],z=g();x.useEffect((function(){B(W?-1:0)}),[W]);var $=F(x.useState(!1),2),J=$[0],Q=$[1],X=q?n:x.Fragment,Y=I?r:x.Fragment;return t(),x.useEffect((function(){var r=T.current;if(r)return e(r)}),[]),x.createElement(X,null,x.createElement(Y,null,x.createElement(K,{menuRef:T,onItemsReachableChange:_,onOpenChange:N},x.createElement(c,{reachable:W,onReachableChange:_,orientation:"vertical",loop:p},x.createElement(o,{trapped:!J&&(m&&s),onMountAutoFocus:y,onUnmountAutoFocus:function(e){J?e.preventDefault():null==h||h(e)}},(function(e){return x.createElement(a,{disableOutsidePointerEvents:O,onEscapeKeyDown:C,onPointerDownOutside:w(M,(function(e){var r=0===e.button&&!1===e.ctrlKey;Q(!O&&r),e.defaultPrevented&&Q(!1)}),{checkForDefaultPrevented:!1}),onFocusOutside:w(D,(function(e){m&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:P,onDismiss:S},(function(r){return x.createElement(u.Root,k({role:"menu"},L,{ref:b(l,T,e.ref,r.ref),anchorRef:d,tabIndex:U,style:E(E({},r.style),{},{outline:"none"},L.style),onBlurCapture:w(L.onBlurCapture,r.onBlurCapture,{checkForDefaultPrevented:!1}),onFocusCapture:w(L.onFocusCapture,r.onFocusCapture,{checkForDefaultPrevented:!1}),onMouseDownCapture:w(L.onMouseDownCapture,r.onMouseDownCapture,{checkForDefaultPrevented:!1}),onTouchStartCapture:w(L.onTouchStartCapture,r.onTouchStartCapture,{checkForDefaultPrevented:!1}),onKeyDownCapture:w(L.onKeyDownCapture,z.onKeyDownCapture),onKeyDown:w(L.onKeyDown,(function(e){var r=T.current;if(e.target===r&&A.includes(e.key)){e.preventDefault();var t=Array.from(r.querySelectorAll(G)),n=j.includes(e.key)?t[0]:t.reverse()[0];null==n||n.focus()}}))}))}))}))))))}));N.displayName="Menu";var G="[".concat("data-radix-menu-item","]:not([data-disabled])"),V=x.forwardRef((function(e,r){var t=e.disabled,n=e.textValue,o=e.onSelect,a=R(e,["disabled","textValue","onSelect"]),u=x.useRef(null),i=h(r,u),c=L("MenuItem"),s=l({disabled:t}),d=F(x.useState(""),2),p=d[0],v=d[1];x.useEffect((function(){var e,r=u.current;r&&v((null!==(e=r.textContent)&&void 0!==e?e:"").trim())}),[a.children]);var m=D({textValue:null!=n?n:p,disabled:t}),y=function(){var e=u.current;if(!t&&e){var r,n=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.dispatchEvent(n),n.defaultPrevented)return;null===(r=c.onOpenChange)||void 0===r||r.call(c,!1)}};return x.useEffect((function(){var e=u.current;if(e){var r=function(e){return null==o?void 0:o(e)};return e.addEventListener("menu.itemSelect",r),function(){return e.removeEventListener("menu.itemSelect",r)}}}),[o]),x.createElement(f,k({role:"menuitem","aria-disabled":t||void 0},a,s,m,S({},"data-radix-menu-item",""),{ref:i,"data-disabled":t?"":void 0,onFocus:w(a.onFocus,s.onFocus),onKeyDown:w(a.onKeyDown,w(s.onKeyDown,(function(e){t||"Enter"!==e.key&&" "!==e.key||y()}))),onMouseDown:w(a.onMouseDown,s.onMouseDown),onMouseUp:w(a.onMouseUp,y),onMouseMove:w(a.onMouseMove,(function(e){t||e.currentTarget.focus()})),onBlur:w(a.onBlur,(function(e){c.onItemsReachableChange(!1)})),onMouseLeave:w(a.onMouseLeave,(function(e){var r;null===(r=c.menuRef.current)||void 0===r||r.focus()}))}))}));exports.MenuItem=V,V.displayName="MenuItem";var U=x.forwardRef((function(e,r){var t=e.checked,n=void 0!==t&&t,o=e.onCheckedChange,a=R(e,["checked","onCheckedChange"]);return x.createElement(_.Provider,{value:n},x.createElement(V,k({role:"menuitemcheckbox","aria-checked":n},a,{ref:r,"data-state":Z(n),onSelect:w(a.onSelect,(function(){return null==o?void 0:o(!n)}),{checkForDefaultPrevented:!1})})))}));exports.MenuCheckboxItem=U,U.displayName="MenuCheckboxItem";var B=x.createContext({}),H=x.forwardRef((function(e,r){var t=e.value,n=e.onValueChange,o=R(e,["value","onValueChange"]),a=v(n),u=x.useMemo((function(){return{value:t,onValueChange:a}}),[t,a]);return x.createElement(B.Provider,{value:u},x.createElement($,k({},o,{ref:r})))}));exports.MenuRadioGroup=H,H.displayName="MenuRadioGroup";var W=x.forwardRef((function(e,r){var t=e.value,n=R(e,["value"]),o=x.useContext(B),a=t===o.value;return x.createElement(_.Provider,{value:a},x.createElement(V,k({role:"menuitemradio","aria-checked":a},n,{ref:r,"data-state":Z(a),onSelect:w(n.onSelect,(function(){var e;return null===(e=o.onValueChange)||void 0===e?void 0:e.call(o,t)}),{checkForDefaultPrevented:!1})})))}));exports.MenuRadioItem=W,W.displayName="MenuRadioItem";var _=x.createContext(!1),z=x.forwardRef((function(e,r){var t=e.as,n=void 0===t?"span":t,o=e.forceMount,a=R(e,["as","forceMount"]),u=x.useContext(_);return x.createElement(p,{present:o||u},x.createElement(f,k({},a,{as:n,ref:r,"data-state":Z(u)})))}));exports.MenuItemIndicator=z,z.displayName="MenuItemIndicator";var $=d(f,{defaultProps:{role:"group"},displayName:"MenuGroup"});exports.MenuGroup=$;var J=d(f,{displayName:"MenuLabel"});exports.MenuLabel=J;var Q=d(f,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});exports.MenuSeparator=Q;var X=d(u.Arrow,{displayName:"MenuArrow"});function Y(e){return e?"open":"closed"}function Z(e){return e?"checked":"unchecked"}exports.MenuArrow=X;var ee=N;exports.Root=ee;var re=$;exports.Group=re;var te=J;exports.Label=te;var ne=V;exports.Item=ne;var oe=U;exports.CheckboxItem=oe;var ae=H;exports.RadioGroup=ae;var ue=W;exports.RadioItem=ue;var ie=z;exports.ItemIndicator=ie;var ce=Q;exports.Separator=ce;var le=X;exports.Arrow=le;
function e(e,t,n){Object.defineProperty(e,t,{get:n,enumerable:!0})}var t=require("aria-hidden").hideOthers,n=require("react-remove-scroll").RemoveScroll,r=require("@radix-ui/react-focus-guards").useFocusGuards,o=require("@radix-ui/react-portal").Portal,u=require("@radix-ui/react-focus-scope").FocusScope,a=require("@radix-ui/react-dismissable-layer").DismissableLayer,c=require("@radix-ui/react-popper"),s=c.Root,i=c.Arrow,l=require("@radix-ui/react-roving-focus"),d=l.RovingFocusGroup,p=l.useRovingFocus,f=require("@radix-ui/react-primitive"),m=f.Primitive,v=f.extendPrimitive,h=require("@radix-ui/react-presence").Presence,x=require("@radix-ui/react-use-callback-ref").useCallbackRef,M=require("@radix-ui/react-context").createContext,y=require("@radix-ui/react-compose-refs"),C=y.composeRefs,b=y.useComposedRefs,w=require("@radix-ui/primitive").composeEventHandlers,D=require("react"),I=D.forwardRef,g=D.createElement,k=D.useRef,P=D.useState,R=D.useEffect,F=D.Fragment,S=D.createContext,O=D.useMemo,q=D.useContext,A=D.useCallback,K={};function E(){const e=k(0),t=k(""),n=A((r=>{t.current=r,window.clearTimeout(e.current),e.current=window.setTimeout((()=>n("")),1e3)}),[]);return{onKeyDownCapture:e=>{if(1===e.key.length&&!(e.ctrlKey||e.altKey||e.metaKey)){const r=e.currentTarget;n(t.current+e.key)," "!==e.key||t.current.startsWith(" ")||e.stopPropagation();const o=document.activeElement,u=o?G(o):void 0,a=function(e,t,n){const r=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,o=n?e.indexOf(n):-1;let u=(a=e,c=Math.max(o,0),a.map(((e,t)=>a[(c+t)%a.length])));var a,c;1===r.length&&(u=u.filter((e=>e!==n)));const s=u.find((e=>e.toLowerCase().startsWith(r.toLowerCase())));return s!==n?s:void 0}(Array.from(r.querySelectorAll(`[${L}]`)).map(G),t.current,u),c=r.querySelector(`[${L}="${a}"]`);c&&setTimeout((()=>c.focus()))}}}}const G=e=>e.getAttribute(L)??"",L="data-radix-menu-typeahead-item";function N(){return(N=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const T=["ArrowDown","PageUp","Home"],V=[...T,"ArrowUp","PageDown","End"],[B,U]=M("Menu"),j=I(((e,t)=>{const{forceMount:n,open:r=!1,...o}=e;return g(h,{present:n||r},g($,N({"data-state":oe(r)},o,{ref:t,open:r})))}));exports.Menu=j;const $=I(((e,c)=>{const{open:i,onOpenChange:l,anchorRef:p,loop:f,trapFocus:m,onOpenAutoFocus:v,onCloseAutoFocus:h,disableOutsidePointerEvents:M,onEscapeKeyDown:y,onPointerDownOutside:b,onFocusOutside:D,onInteractOutside:I,onDismiss:S,disableOutsideScroll:O,portalled:q,...A}=e,K=x(l),G=k(null),[L,U]=P(0),[j,$]=P(!1),W=E();R((()=>{U(j?-1:0)}),[j]);const[z,J]=P(!1),Q=q?o:F,X=O?n:F;return r(),R((()=>{const e=G.current;if(e)return t(e)}),[]),g(Q,null,g(X,null,g(B,{menuRef:G,onItemsReachableChange:$,onOpenChange:K},g(d,{reachable:j,onReachableChange:$,orientation:"vertical",loop:f},g(u,{trapped:!z&&(m&&i),onMountAutoFocus:v,onUnmountAutoFocus:e=>{z?e.preventDefault():h?.(e)}},(e=>g(a,{disableOutsidePointerEvents:M,onEscapeKeyDown:y,onPointerDownOutside:w(b,(e=>{const t=0===e.button&&!1===e.ctrlKey;J(!M&&t),e.defaultPrevented&&J(!1)}),{checkForDefaultPrevented:!1}),onFocusOutside:w(D,(e=>{m&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:I,onDismiss:S},(t=>g(s,N({role:"menu"},A,{ref:C(c,G,e.ref,t.ref),anchorRef:p,tabIndex:L,style:{...t.style,outline:"none",...A.style},onBlurCapture:w(A.onBlurCapture,t.onBlurCapture,{checkForDefaultPrevented:!1}),onFocusCapture:w(A.onFocusCapture,t.onFocusCapture,{checkForDefaultPrevented:!1}),onMouseDownCapture:w(A.onMouseDownCapture,t.onMouseDownCapture,{checkForDefaultPrevented:!1}),onTouchStartCapture:w(A.onTouchStartCapture,t.onTouchStartCapture,{checkForDefaultPrevented:!1}),onKeyDownCapture:w(A.onKeyDownCapture,W.onKeyDownCapture),onKeyDown:w(A.onKeyDown,(e=>{const t=G.current;if(e.target===t&&V.includes(e.key)){e.preventDefault();const n=Array.from(t.querySelectorAll(H));(T.includes(e.key)?n[0]:n.reverse()[0])?.focus?.()}}))}))))))))))}));j.displayName="Menu";const H="[data-radix-menu-item]:not([data-disabled])",W=I(((e,t)=>{const{disabled:n,textValue:r,onSelect:o,...u}=e,a=k(null),c=b(t,a),s=U("MenuItem"),i=p({disabled:n}),[l,d]=P("");R((()=>{const e=a.current;e&&d((e.textContent??"").trim())}),[u.children]);const f=function({textValue:e,disabled:t}){return{[L]:t?void 0:e}}({textValue:r??l,disabled:n}),v=()=>{const e=a.current;if(!n&&e){const t=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.dispatchEvent(t),t.defaultPrevented)return;s.onOpenChange?.(!1)}};return R((()=>{const e=a.current;if(e){const t=e=>o?.(e);return e.addEventListener("menu.itemSelect",t),()=>e.removeEventListener("menu.itemSelect",t)}}),[o]),g(m,N({role:"menuitem","aria-disabled":n||void 0},u,i,f,{"data-radix-menu-item":"",ref:c,"data-disabled":n?"":void 0,onFocus:w(u.onFocus,i.onFocus),onKeyDown:w(u.onKeyDown,w(i.onKeyDown,(e=>{n||"Enter"!==e.key&&" "!==e.key||v()}))),onMouseDown:w(u.onMouseDown,i.onMouseDown),onMouseUp:w(u.onMouseUp,v),onMouseMove:w(u.onMouseMove,(e=>{if(!n){e.currentTarget.focus()}})),onBlur:w(u.onBlur,(e=>{s.onItemsReachableChange(!1)})),onMouseLeave:w(u.onMouseLeave,(e=>{s.menuRef.current?.focus?.()}))}))}));exports.MenuItem=W,W.displayName="MenuItem";const z=I(((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return g(Z.Provider,{value:n},g(W,N({role:"menuitemcheckbox","aria-checked":n},o,{ref:t,"data-state":ue(n),onSelect:w(o.onSelect,(()=>r?.(!n)),{checkForDefaultPrevented:!1})})))}));exports.MenuCheckboxItem=z,z.displayName="MenuCheckboxItem";const J=S({}),Q=I(((e,t)=>{const{value:n,onValueChange:r,...o}=e,u=x(r),a=O((()=>({value:n,onValueChange:u})),[n,u]);return g(J.Provider,{value:a},g(ee,N({},o,{ref:t})))}));exports.MenuRadioGroup=Q,Q.displayName="MenuRadioGroup";const X=I(((e,t)=>{const{value:n,...r}=e,o=q(J),u=n===o.value;return g(Z.Provider,{value:u},g(W,N({role:"menuitemradio","aria-checked":u},r,{ref:t,"data-state":ue(u),onSelect:w(r.onSelect,(()=>o.onValueChange?.(n)),{checkForDefaultPrevented:!1})})))}));exports.MenuRadioItem=X,X.displayName="MenuRadioItem";const Y="span",Z=S(!1),_=I(((e,t)=>{const{as:n=Y,forceMount:r,...o}=e,u=q(Z);return g(h,{present:r||u},g(m,N({},o,{as:n,ref:t,"data-state":ue(u)})))}));exports.MenuItemIndicator=_,_.displayName="MenuItemIndicator";const ee=v(m,{defaultProps:{role:"group"},displayName:"MenuGroup"});exports.MenuGroup=ee;const te=v(m,{displayName:"MenuLabel"});exports.MenuLabel=te;const ne=v(m,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});exports.MenuSeparator=ne;const re=v(i,{displayName:"MenuArrow"});function oe(e){return e?"open":"closed"}function ue(e){return e?"checked":"unchecked"}exports.MenuArrow=re;const ae=j;exports.Root=ae;const ce=ee;exports.Group=ce;const se=te;exports.Label=se;const ie=W;exports.Item=ie;const le=z;exports.CheckboxItem=le;const de=Q;exports.RadioGroup=de;const pe=X;exports.RadioItem=pe;const fe=_;exports.ItemIndicator=fe;const me=ne;exports.Separator=me;const ve=re;exports.Arrow=ve,e(K,"Arrow",(function(){return ve})),e(K,"Separator",(function(){return me})),e(K,"ItemIndicator",(function(){return fe})),e(K,"RadioItem",(function(){return pe})),e(K,"RadioGroup",(function(){return de})),e(K,"CheckboxItem",(function(){return le})),e(K,"Item",(function(){return ie})),e(K,"Label",(function(){return se})),e(K,"Group",(function(){return ce})),e(K,"Root",(function(){return ae})),e(K,"MenuArrow",(function(){return re})),e(K,"MenuSeparator",(function(){return ne})),e(K,"MenuItemIndicator",(function(){return _})),e(K,"MenuRadioItem",(function(){return X})),e(K,"MenuRadioGroup",(function(){return Q})),e(K,"MenuCheckboxItem",(function(){return z})),e(K,"MenuItem",(function(){return W})),e(K,"MenuLabel",(function(){return te})),e(K,"MenuGroup",(function(){return ee})),e(K,"Menu",(function(){return j}));
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{hideOthers as e}from"aria-hidden";import{RemoveScroll as t}from"react-remove-scroll";import{useFocusGuards as o}from"@radix-ui/react-focus-guards";import{Portal as r}from"@radix-ui/react-portal";import{FocusScope as n}from"@radix-ui/react-focus-scope";import{DismissableLayer as a}from"@radix-ui/react-dismissable-layer";import*as u from"@radix-ui/react-popper";import{RovingFocusGroup as c,useRovingFocus as s}from"@radix-ui/react-roving-focus";import{Primitive as i,extendPrimitive as l}from"@radix-ui/react-primitive";import{Presence as d}from"@radix-ui/react-presence";import{useCallbackRef as m}from"@radix-ui/react-use-callback-ref";import{createContext as p}from"@radix-ui/react-context";import{composeRefs as f,useComposedRefs as v}from"@radix-ui/react-compose-refs";import{composeEventHandlers as M}from"@radix-ui/primitive";import*as h from"react";function x(){const e=h.useRef(0),t=h.useRef(""),o=h.useCallback((r=>{t.current=r,window.clearTimeout(e.current),e.current=window.setTimeout((()=>o("")),1e3)}),[]);return{onKeyDownCapture:e=>{if(1===e.key.length&&!(e.ctrlKey||e.altKey||e.metaKey)){const r=e.currentTarget;o(t.current+e.key)," "!==e.key||t.current.startsWith(" ")||e.stopPropagation();const n=document.activeElement,a=n?y(n):void 0,u=function(e,t,o){const r=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,n=o?e.indexOf(o):-1;let a=(u=e,c=Math.max(n,0),u.map(((e,t)=>u[(c+t)%u.length])));var u,c;1===r.length&&(a=a.filter((e=>e!==o)));const s=a.find((e=>e.toLowerCase().startsWith(r.toLowerCase())));return s!==o?s:void 0}(Array.from(r.querySelectorAll("[".concat(w,"]"))).map(y),t.current,a),c=r.querySelector("[".concat(w,'="').concat(u,'"]'));c&&setTimeout((()=>c.focus()))}}}}const y=e=>{var t;return null!==(t=e.getAttribute(w))&&void 0!==t?t:""},w="data-radix-menu-typeahead-item";function C(){return(C=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e}).apply(this,arguments)}const b=["ArrowDown","PageUp","Home"],D=[...b,"ArrowUp","PageDown","End"],[E,I]=p("Menu");export const Menu=h.forwardRef(((e,t)=>{const{forceMount:o,open:r=!1,...n}=e;return h.createElement(d,{present:o||r},h.createElement(R,C({"data-state":S(r)},n,{ref:t,open:r})))}));const R=h.forwardRef(((s,i)=>{const{open:l,onOpenChange:d,anchorRef:p,loop:v,trapFocus:y,onOpenAutoFocus:w,onCloseAutoFocus:I,disableOutsidePointerEvents:R,onEscapeKeyDown:g,onPointerDownOutside:F,onFocusOutside:P,onInteractOutside:S,onDismiss:A,disableOutsideScroll:O,portalled:K,...G}=s,L=m(d),N=h.useRef(null),[T,V]=h.useState(0),[B,U]=h.useState(!1),q=x();h.useEffect((()=>{V(B?-1:0)}),[B]);const[j,W]=h.useState(!1),z=K?r:h.Fragment,H=O?t:h.Fragment;return o(),h.useEffect((()=>{const t=N.current;if(t)return e(t)}),[]),h.createElement(z,null,h.createElement(H,null,h.createElement(E,{menuRef:N,onItemsReachableChange:U,onOpenChange:L},h.createElement(c,{reachable:B,onReachableChange:U,orientation:"vertical",loop:v},h.createElement(n,{trapped:!j&&(y&&l),onMountAutoFocus:w,onUnmountAutoFocus:e=>{j?e.preventDefault():null==I||I(e)}},(e=>h.createElement(a,{disableOutsidePointerEvents:R,onEscapeKeyDown:g,onPointerDownOutside:M(F,(e=>{const t=0===e.button&&!1===e.ctrlKey;W(!R&&t),e.defaultPrevented&&W(!1)}),{checkForDefaultPrevented:!1}),onFocusOutside:M(P,(e=>{y&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:S,onDismiss:A},(t=>h.createElement(u.Root,C({role:"menu"},G,{ref:f(i,N,e.ref,t.ref),anchorRef:p,tabIndex:T,style:{...t.style,outline:"none",...G.style},onBlurCapture:M(G.onBlurCapture,t.onBlurCapture,{checkForDefaultPrevented:!1}),onFocusCapture:M(G.onFocusCapture,t.onFocusCapture,{checkForDefaultPrevented:!1}),onMouseDownCapture:M(G.onMouseDownCapture,t.onMouseDownCapture,{checkForDefaultPrevented:!1}),onTouchStartCapture:M(G.onTouchStartCapture,t.onTouchStartCapture,{checkForDefaultPrevented:!1}),onKeyDownCapture:M(G.onKeyDownCapture,q.onKeyDownCapture),onKeyDown:M(G.onKeyDown,(e=>{const t=N.current;if(e.target===t&&D.includes(e.key)){e.preventDefault();const o=Array.from(t.querySelectorAll(k)),r=b.includes(e.key)?o[0]:o.reverse()[0];null==r||r.focus()}}))}))))))))))}));Menu.displayName="Menu";const k="[".concat("data-radix-menu-item","]:not([data-disabled])");export const MenuItem=h.forwardRef(((e,t)=>{const{disabled:o,textValue:r,onSelect:n,...a}=e,u=h.useRef(null),c=v(t,u),l=I("MenuItem"),d=s({disabled:o}),[m,p]=h.useState("");h.useEffect((()=>{const e=u.current;var t;e&&p((null!==(t=e.textContent)&&void 0!==t?t:"").trim())}),[a.children]);const f=function({textValue:e,disabled:t}){return{[w]:t?void 0:e}}({textValue:null!=r?r:m,disabled:o}),x=()=>{const e=u.current;if(!o&&e){var t;const o=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.dispatchEvent(o),o.defaultPrevented)return;null===(t=l.onOpenChange)||void 0===t||t.call(l,!1)}};return h.useEffect((()=>{const e=u.current;if(e){const t=e=>null==n?void 0:n(e);return e.addEventListener("menu.itemSelect",t),()=>e.removeEventListener("menu.itemSelect",t)}}),[n]),h.createElement(i,C({role:"menuitem","aria-disabled":o||void 0},a,d,f,{"data-radix-menu-item":"",ref:c,"data-disabled":o?"":void 0,onFocus:M(a.onFocus,d.onFocus),onKeyDown:M(a.onKeyDown,M(d.onKeyDown,(e=>{o||"Enter"!==e.key&&" "!==e.key||x()}))),onMouseDown:M(a.onMouseDown,d.onMouseDown),onMouseUp:M(a.onMouseUp,x),onMouseMove:M(a.onMouseMove,(e=>{if(!o){e.currentTarget.focus()}})),onBlur:M(a.onBlur,(e=>{l.onItemsReachableChange(!1)})),onMouseLeave:M(a.onMouseLeave,(e=>{var t;null===(t=l.menuRef.current)||void 0===t||t.focus()}))}))}));MenuItem.displayName="MenuItem";export const MenuCheckboxItem=h.forwardRef(((e,t)=>{const{checked:o=!1,onCheckedChange:r,...n}=e;return h.createElement(P.Provider,{value:o},h.createElement(MenuItem,C({role:"menuitemcheckbox","aria-checked":o},n,{ref:t,"data-state":A(o),onSelect:M(n.onSelect,(()=>null==r?void 0:r(!o)),{checkForDefaultPrevented:!1})})))}));MenuCheckboxItem.displayName="MenuCheckboxItem";const g=h.createContext({});export const MenuRadioGroup=h.forwardRef(((e,t)=>{const{value:o,onValueChange:r,...n}=e,a=m(r),u=h.useMemo((()=>({value:o,onValueChange:a})),[o,a]);return h.createElement(g.Provider,{value:u},h.createElement(MenuGroup,C({},n,{ref:t})))}));MenuRadioGroup.displayName="MenuRadioGroup";export const MenuRadioItem=h.forwardRef(((e,t)=>{const{value:o,...r}=e,n=h.useContext(g),a=o===n.value;return h.createElement(P.Provider,{value:a},h.createElement(MenuItem,C({role:"menuitemradio","aria-checked":a},r,{ref:t,"data-state":A(a),onSelect:M(r.onSelect,(()=>{var e;return null===(e=n.onValueChange)||void 0===e?void 0:e.call(n,o)}),{checkForDefaultPrevented:!1})})))}));MenuRadioItem.displayName="MenuRadioItem";const F="span",P=h.createContext(!1);export const MenuItemIndicator=h.forwardRef(((e,t)=>{const{as:o=F,forceMount:r,...n}=e,a=h.useContext(P);return h.createElement(d,{present:r||a},h.createElement(i,C({},n,{as:o,ref:t,"data-state":A(a)})))}));MenuItemIndicator.displayName="MenuItemIndicator";export const MenuGroup=l(i,{defaultProps:{role:"group"},displayName:"MenuGroup"});export const MenuLabel=l(i,{displayName:"MenuLabel"});export const MenuSeparator=l(i,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});export const MenuArrow=l(u.Arrow,{displayName:"MenuArrow"});function S(e){return e?"open":"closed"}function A(e){return e?"checked":"unchecked"}export const Root=Menu;export const Group=MenuGroup;export const Label=MenuLabel;export const Item=MenuItem;export const CheckboxItem=MenuCheckboxItem;export const RadioGroup=MenuRadioGroup;export const RadioItem=MenuRadioItem;export const ItemIndicator=MenuItemIndicator;export const Separator=MenuSeparator;export const Arrow=MenuArrow;
function e(e,t,o){Object.defineProperty(e,t,{get:o,enumerable:!0})}import{hideOthers as t}from"aria-hidden";import{RemoveScroll as o}from"react-remove-scroll";import{useFocusGuards as n}from"@radix-ui/react-focus-guards";import{Portal as r}from"@radix-ui/react-portal";import{FocusScope as u}from"@radix-ui/react-focus-scope";import{DismissableLayer as a}from"@radix-ui/react-dismissable-layer";import{Root as c,Arrow as i}from"@radix-ui/react-popper";import{RovingFocusGroup as s,useRovingFocus as d}from"@radix-ui/react-roving-focus";import{Primitive as p,extendPrimitive as l}from"@radix-ui/react-primitive";import{Presence as m}from"@radix-ui/react-presence";import{useCallbackRef as f}from"@radix-ui/react-use-callback-ref";import{createContext as M}from"@radix-ui/react-context";import{composeRefs as h,useComposedRefs as x}from"@radix-ui/react-compose-refs";import{composeEventHandlers as I}from"@radix-ui/primitive";import{forwardRef as v,createElement as y,useRef as b,useState as C,useEffect as w,Fragment as D,createContext as k,useMemo as R,useContext as g,useCallback as P}from"react";var S={};function A(){const e=b(0),t=b(""),o=P((n=>{t.current=n,window.clearTimeout(e.current),e.current=window.setTimeout((()=>o("")),1e3)}),[]);return{onKeyDownCapture:e=>{if(1===e.key.length&&!(e.ctrlKey||e.altKey||e.metaKey)){const n=e.currentTarget;o(t.current+e.key)," "!==e.key||t.current.startsWith(" ")||e.stopPropagation();const r=document.activeElement,u=r?F(r):void 0,a=function(e,t,o){const n=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,r=o?e.indexOf(o):-1;let u=(a=e,c=Math.max(r,0),a.map(((e,t)=>a[(c+t)%a.length])));var a,c;1===n.length&&(u=u.filter((e=>e!==o)));const i=u.find((e=>e.toLowerCase().startsWith(n.toLowerCase())));return i!==o?i:void 0}(Array.from(n.querySelectorAll(`[${G}]`)).map(F),t.current,u),c=n.querySelector(`[${G}="${a}"]`);c&&setTimeout((()=>c.focus()))}}}}const F=e=>e.getAttribute(G)??"",G="data-radix-menu-typeahead-item";function O(){return(O=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e}).apply(this,arguments)}const K=["ArrowDown","PageUp","Home"],L=[...K,"ArrowUp","PageDown","End"],[E,N]=M("Menu");export const Menu=v(((e,t)=>{const{forceMount:o,open:n=!1,...r}=e;return y(m,{present:o||n},y(T,O({"data-state":q(n)},r,{ref:t,open:n})))}));const T=v(((e,i)=>{const{open:d,onOpenChange:p,anchorRef:l,loop:m,trapFocus:M,onOpenAutoFocus:x,onCloseAutoFocus:v,disableOutsidePointerEvents:k,onEscapeKeyDown:R,onPointerDownOutside:g,onFocusOutside:P,onInteractOutside:S,onDismiss:F,disableOutsideScroll:G,portalled:N,...T}=e,B=f(p),U=b(null),[j,q]=C(0),[$,W]=C(!1),z=A();w((()=>{q($?-1:0)}),[$]);const[H,J]=C(!1),Q=N?r:D,X=G?o:D;return n(),w((()=>{const e=U.current;if(e)return t(e)}),[]),y(Q,null,y(X,null,y(E,{menuRef:U,onItemsReachableChange:W,onOpenChange:B},y(s,{reachable:$,onReachableChange:W,orientation:"vertical",loop:m},y(u,{trapped:!H&&(M&&d),onMountAutoFocus:x,onUnmountAutoFocus:e=>{H?e.preventDefault():v?.(e)}},(e=>y(a,{disableOutsidePointerEvents:k,onEscapeKeyDown:R,onPointerDownOutside:I(g,(e=>{const t=0===e.button&&!1===e.ctrlKey;J(!k&&t),e.defaultPrevented&&J(!1)}),{checkForDefaultPrevented:!1}),onFocusOutside:I(P,(e=>{M&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:S,onDismiss:F},(t=>y(c,O({role:"menu"},T,{ref:h(i,U,e.ref,t.ref),anchorRef:l,tabIndex:j,style:{...t.style,outline:"none",...T.style},onBlurCapture:I(T.onBlurCapture,t.onBlurCapture,{checkForDefaultPrevented:!1}),onFocusCapture:I(T.onFocusCapture,t.onFocusCapture,{checkForDefaultPrevented:!1}),onMouseDownCapture:I(T.onMouseDownCapture,t.onMouseDownCapture,{checkForDefaultPrevented:!1}),onTouchStartCapture:I(T.onTouchStartCapture,t.onTouchStartCapture,{checkForDefaultPrevented:!1}),onKeyDownCapture:I(T.onKeyDownCapture,z.onKeyDownCapture),onKeyDown:I(T.onKeyDown,(e=>{const t=U.current;if(e.target===t&&L.includes(e.key)){e.preventDefault();const o=Array.from(t.querySelectorAll(V));(K.includes(e.key)?o[0]:o.reverse()[0])?.focus?.()}}))}))))))))))}));Menu.displayName="Menu";const V="[data-radix-menu-item]:not([data-disabled])";export const MenuItem=v(((e,t)=>{const{disabled:o,textValue:n,onSelect:r,...u}=e,a=b(null),c=x(t,a),i=N("MenuItem"),s=d({disabled:o}),[l,m]=C("");w((()=>{const e=a.current;e&&m((e.textContent??"").trim())}),[u.children]);const f=function({textValue:e,disabled:t}){return{[G]:t?void 0:e}}({textValue:n??l,disabled:o}),M=()=>{const e=a.current;if(!o&&e){const t=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.dispatchEvent(t),t.defaultPrevented)return;i.onOpenChange?.(!1)}};return w((()=>{const e=a.current;if(e){const t=e=>r?.(e);return e.addEventListener("menu.itemSelect",t),()=>e.removeEventListener("menu.itemSelect",t)}}),[r]),y(p,O({role:"menuitem","aria-disabled":o||void 0},u,s,f,{"data-radix-menu-item":"",ref:c,"data-disabled":o?"":void 0,onFocus:I(u.onFocus,s.onFocus),onKeyDown:I(u.onKeyDown,I(s.onKeyDown,(e=>{o||"Enter"!==e.key&&" "!==e.key||M()}))),onMouseDown:I(u.onMouseDown,s.onMouseDown),onMouseUp:I(u.onMouseUp,M),onMouseMove:I(u.onMouseMove,(e=>{if(!o){e.currentTarget.focus()}})),onBlur:I(u.onBlur,(e=>{i.onItemsReachableChange(!1)})),onMouseLeave:I(u.onMouseLeave,(e=>{i.menuRef.current?.focus?.()}))}))}));MenuItem.displayName="MenuItem";export const MenuCheckboxItem=v(((e,t)=>{const{checked:o=!1,onCheckedChange:n,...r}=e;return y(j.Provider,{value:o},y(MenuItem,O({role:"menuitemcheckbox","aria-checked":o},r,{ref:t,"data-state":$(o),onSelect:I(r.onSelect,(()=>n?.(!o)),{checkForDefaultPrevented:!1})})))}));MenuCheckboxItem.displayName="MenuCheckboxItem";const B=k({});export const MenuRadioGroup=v(((e,t)=>{const{value:o,onValueChange:n,...r}=e,u=f(n),a=R((()=>({value:o,onValueChange:u})),[o,u]);return y(B.Provider,{value:a},y(MenuGroup,O({},r,{ref:t})))}));MenuRadioGroup.displayName="MenuRadioGroup";export const MenuRadioItem=v(((e,t)=>{const{value:o,...n}=e,r=g(B),u=o===r.value;return y(j.Provider,{value:u},y(MenuItem,O({role:"menuitemradio","aria-checked":u},n,{ref:t,"data-state":$(u),onSelect:I(n.onSelect,(()=>r.onValueChange?.(o)),{checkForDefaultPrevented:!1})})))}));MenuRadioItem.displayName="MenuRadioItem";const U="span",j=k(!1);export const MenuItemIndicator=v(((e,t)=>{const{as:o=U,forceMount:n,...r}=e,u=g(j);return y(m,{present:n||u},y(p,O({},r,{as:o,ref:t,"data-state":$(u)})))}));MenuItemIndicator.displayName="MenuItemIndicator";export const MenuGroup=l(p,{defaultProps:{role:"group"},displayName:"MenuGroup"});export const MenuLabel=l(p,{displayName:"MenuLabel"});export const MenuSeparator=l(p,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});export const MenuArrow=l(i,{displayName:"MenuArrow"});function q(e){return e?"open":"closed"}function $(e){return e?"checked":"unchecked"}export const Root=Menu;export const Group=MenuGroup;export const Label=MenuLabel;export const Item=MenuItem;export const CheckboxItem=MenuCheckboxItem;export const RadioGroup=MenuRadioGroup;export const RadioItem=MenuRadioItem;export const ItemIndicator=MenuItemIndicator;export const Separator=MenuSeparator;export const Arrow=MenuArrow;e(S,"Arrow",(function(){return Arrow})),e(S,"Separator",(function(){return Separator})),e(S,"ItemIndicator",(function(){return ItemIndicator})),e(S,"RadioItem",(function(){return RadioItem})),e(S,"RadioGroup",(function(){return RadioGroup})),e(S,"CheckboxItem",(function(){return CheckboxItem})),e(S,"Item",(function(){return Item})),e(S,"Label",(function(){return Label})),e(S,"Group",(function(){return Group})),e(S,"Root",(function(){return Root})),e(S,"MenuArrow",(function(){return MenuArrow})),e(S,"MenuSeparator",(function(){return MenuSeparator})),e(S,"MenuItemIndicator",(function(){return MenuItemIndicator})),e(S,"MenuRadioItem",(function(){return MenuRadioItem})),e(S,"MenuRadioGroup",(function(){return MenuRadioGroup})),e(S,"MenuCheckboxItem",(function(){return MenuCheckboxItem})),e(S,"MenuItem",(function(){return MenuItem})),e(S,"MenuLabel",(function(){return MenuLabel})),e(S,"MenuGroup",(function(){return MenuGroup})),e(S,"Menu",(function(){return Menu}));
//# sourceMappingURL=index.module.js.map
{
"name": "@radix-ui/react-menu",
"version": "0.0.9",
"version": "0.0.10",
"license": "MIT",

@@ -22,9 +22,9 @@ "source": "src/index.ts",

"@radix-ui/react-context": "0.0.1",
"@radix-ui/react-dismissable-layer": "0.0.6",
"@radix-ui/react-dismissable-layer": "0.0.7",
"@radix-ui/react-focus-guards": "0.0.3",
"@radix-ui/react-focus-scope": "0.0.6",
"@radix-ui/react-polymorphic": "0.0.6",
"@radix-ui/react-popper": "0.0.8",
"@radix-ui/react-popper": "0.0.9",
"@radix-ui/react-portal": "0.0.6",
"@radix-ui/react-presence": "0.0.7",
"@radix-ui/react-presence": "0.0.8",
"@radix-ui/react-primitive": "0.0.6",

@@ -31,0 +31,0 @@ "@radix-ui/react-roving-focus": "0.0.6",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc