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

@reach/combobox

Package Overview
Dependencies
Maintainers
4
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reach/combobox - npm Package Compare versions

Comparing version 0.10.1 to 0.10.2

18

dist/combobox.cjs.development.js

@@ -101,3 +101,3 @@ 'use strict';

var reducer = function reducer(data, event) {
var nextState = _extends({}, data, {
var nextState = _extends(_extends({}, data), {}, {
lastEventType: event.type

@@ -109,3 +109,3 @@ });

case INITIAL_CHANGE:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: null,

@@ -117,3 +117,3 @@ value: event.value

case OPEN_WITH_BUTTON:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: findNavigationValue(nextState, event)

@@ -123,3 +123,3 @@ });

case CLEAR:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
value: "",

@@ -131,3 +131,3 @@ navigationValue: null

case ESCAPE:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: null

@@ -137,3 +137,3 @@ });

case SELECT_WITH_CLICK:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
value: event.value,

@@ -144,3 +144,3 @@ navigationValue: null

case SELECT_WITH_KEYBOARD:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
value: data.navigationValue,

@@ -151,3 +151,3 @@ navigationValue: null

case CLOSE_WITH_BUTTON:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: null

@@ -160,3 +160,3 @@ });

case FOCUS:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: findNavigationValue(nextState, event)

@@ -163,0 +163,0 @@ });

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

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=e(t);require("prop-types");var a,r,o,u,i,l=require("@reach/utils"),c=require("@reach/descendants"),s=require("highlight-words-core"),v=require("@reach/auto-id"),d=require("@reach/popover"),f=e(d);function E(){return(E=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}function p(e,t){if(null==e)return{};var n,a,r={},o=Object.keys(e);for(a=0;a<o.length;a++)t.indexOf(n=o[a])>=0||(r[n]=e[n]);return r}var C="IDLE",b="SUGGESTING",T="NAVIGATING",x="INTERACTING",I={initial:C,states:(i={},i.IDLE={on:(a={},a.BLUR=C,a.CLEAR=C,a.CHANGE=b,a.INITIAL_CHANGE=C,a.FOCUS=b,a.NAVIGATE=T,a.OPEN_WITH_BUTTON=b,a)},i[b]={on:(r={},r.CHANGE=b,r.FOCUS=b,r.NAVIGATE=T,r.CLEAR=C,r.ESCAPE=C,r.BLUR=C,r.SELECT_WITH_CLICK=C,r.INTERACT=x,r.CLOSE_WITH_BUTTON=C,r)},i[T]={on:(o={},o.CHANGE=b,o.FOCUS=b,o.CLEAR=C,o.BLUR=C,o.ESCAPE=C,o.NAVIGATE=T,o.SELECT_WITH_CLICK=C,o.SELECT_WITH_KEYBOARD=C,o.CLOSE_WITH_BUTTON=C,o.INTERACT=x,o)},i[x]={on:(u={},u.CLEAR=C,u.CHANGE=b,u.FOCUS=b,u.BLUR=C,u.ESCAPE=C,u.NAVIGATE=T,u.CLOSE_WITH_BUTTON=C,u.SELECT_WITH_CLICK=C,u)},i)},A=function(e,t){var n=E({},e,{lastEventType:t.type});switch(t.type){case"CHANGE":case"INITIAL_CHANGE":return E({},n,{navigationValue:null,value:t.value});case"NAVIGATE":case"OPEN_WITH_BUTTON":return E({},n,{navigationValue:g(n,t)});case"CLEAR":return E({},n,{value:"",navigationValue:null});case"BLUR":case"ESCAPE":return E({},n,{navigationValue:null});case"SELECT_WITH_CLICK":return E({},n,{value:t.value,navigationValue:null});case"SELECT_WITH_KEYBOARD":return E({},n,{value:e.navigationValue,navigationValue:null});case"CLOSE_WITH_BUTTON":return E({},n,{navigationValue:null});case"INTERACT":return n;case"FOCUS":return E({},n,{navigationValue:g(n,t)});default:return n}};function h(e){return[b,T,x].includes(e)}function g(e,t){return t.value?t.value:t.persistSelection?e.value:null}var m=c.createDescendantContext("ComboboxDescendantContext"),R=l.createNamedContext("ComboboxContext",{}),N=l.createNamedContext("OptionContext",{}),O=l.forwardRefWithAs((function(e,a){var r=e.onSelect,o=e.openOnFocus,u=void 0!==o&&o,i=e.children,s=e.as,d=void 0===s?"div":s,f=e["aria-label"],C=e["aria-labelledby"],b=p(e,["onSelect","openOnFocus","children","as","aria-label","aria-labelledby"]),T=c.useDescendants(),x=T[0],g=T[1],N=t.useRef(),O=t.useRef(),S=t.useRef(),L=t.useRef(),_=t.useRef(),w=function(e,n,a){var r=t.useState(e.initial),o=r[0],u=r[1],i=t.useReducer(n,{value:"",navigationValue:null}),l=i[1];return[o,i[0],function(t,n){void 0===n&&(n={});var a=e.states[o],r=a&&a.on[t];if(r)return l(E({type:t,state:o,nextState:o},n)),void u(r)}]}(I,A),y=w[0],H=w[1],G=w[2];!function(e,t){l.useIsomorphicLayoutEffect((function(){"NAVIGATE"!==e&&"ESCAPE"!==e&&"SELECT_WITH_CLICK"!==e&&"OPEN_WITH_BUTTON"!==e||t.current.focus()}),[t,e])}(H.lastEventType,N);var V=v.useId(b.id),D=V?l.makeId("listbox",V):"listbox",k={ariaLabel:f,ariaLabelledby:C,autocompletePropRef:L,buttonRef:S,comboboxId:V,data:H,inputRef:N,isExpanded:h(y),listboxId:D,onSelect:r||l.noop,openOnFocus:u,persistSelectionRef:_,popoverRef:O,state:y,transition:G};return t.useEffect((function(){return l.checkStyles("combobox")}),[]),n.createElement(c.DescendantProvider,{context:m,items:x,set:g},n.createElement(R.Provider,{value:k},n.createElement(d,Object.assign({},b,{"data-reach-combobox":"",ref:a}),l.isFunction(i)?i({id:V,isExpanded:h(y)}):i)))})),S=l.forwardRefWithAs((function(e,a){var r=e.as,o=void 0===r?"input":r,u=e.selectOnClick,i=void 0!==u&&u,c=e.autocomplete,s=void 0===c||c,v=e.onClick,d=e.onChange,f=e.onKeyDown,E=e.onBlur,C=e.onFocus,b=e.value,I=p(e,["as","selectOnClick","autocomplete","onClick","onChange","onKeyDown","onBlur","onFocus","value"]),A=t.useRef(b).current,h=t.useRef(!1);l.useUpdateEffect((function(){h.current=!0}),[b]);var g=t.useContext(R),m=g.data,N=m.navigationValue,O=m.value,S=m.lastEventType,L=g.inputRef,_=g.state,w=g.transition,y=g.listboxId,H=g.autocompletePropRef,k=g.openOnFocus,W=g.isExpanded,B=g.ariaLabel,U=g.ariaLabelledby,P=l.useForkedRef(L,a),F=t.useRef(!1),K=G(),j=V(),q=null!=b;l.useIsomorphicLayoutEffect((function(){H.current=s}),[s,H]);var M=t.useCallback((function(e){""===e.trim()?w("CLEAR"):w(e!==A||h.current?"CHANGE":"INITIAL_CHANGE",{value:e})}),[A,w]);t.useEffect((function(){!q||b===O||""===b.trim()&&""===(O||"").trim()||M(b)}),[b,M,q,O]);var Y=!s||_!==T&&_!==x?b||O:N||b||O;return n.createElement(o,Object.assign({"aria-activedescendant":N?String(D(N)):void 0,"aria-autocomplete":"both","aria-controls":y,"aria-expanded":W,"aria-haspopup":"listbox","aria-label":B,"aria-labelledby":B?void 0:U,role:"combobox"},I,{"data-reach-combobox-input":"",ref:P,onBlur:l.wrapEvent(E,j),onChange:l.wrapEvent(d,(function(e){q||M(e.target.value)})),onClick:l.wrapEvent(v,(function(){F.current&&(F.current=!1,L.current.select())})),onFocus:l.wrapEvent(C,(function(){i&&(F.current=!0),k&&"SELECT_WITH_CLICK"!==S&&w("FOCUS")})),onKeyDown:l.wrapEvent(f,K),value:Y||""}))})),L=t.forwardRef((function(e,a){var r=e.children,o=e.portal,u=void 0===o||o,i=e.onKeyDown,c=e.onBlur,s=p(e,["children","portal","onKeyDown","onBlur"]),v=t.useContext(R),E=v.inputRef,C=v.isExpanded,b=l.useForkedRef(v.popoverRef,a),T=G(),x=V(),I={"data-reach-combobox-popover":"",onKeyDown:l.wrapEvent(i,T),onBlur:l.wrapEvent(c,x),hidden:!C,tabIndex:-1,children:r};return u?n.createElement(f,Object.assign({},s,{ref:b,position:d.positionMatchWidth,targetRef:E},I)):n.createElement("div",Object.assign({ref:b},s,I))})),_=l.forwardRefWithAs((function(e,a){var r=e.persistSelection,o=void 0!==r&&r,u=e.as,i=void 0===u?"ul":u,l=p(e,["persistSelection","as"]),c=t.useContext(R),s=c.listboxId;return o&&(c.persistSelectionRef.current=!0),n.createElement(i,Object.assign({role:"listbox"},l,{ref:a,"data-reach-combobox-list":"",id:s}))})),w=l.forwardRefWithAs((function(e,a){var r=e.as,o=void 0===r?"li":r,u=e.children,i=e.value,s=e.onClick,v=p(e,["as","children","value","onClick"]),d=t.useContext(R),f=d.onSelect,E=d.data.navigationValue,C=d.transition,b=t.useRef(null),T=l.useForkedRef(a,b),x=c.useDescendant({context:m,element:b.current,value:i}),I=E===i;return n.createElement(N.Provider,{value:{value:i,index:x}},n.createElement(o,Object.assign({"aria-selected":I,role:"option"},v,{"data-reach-combobox-option":"",ref:T,id:String(D(i)),"data-highlighted":I?"":void 0,tabIndex:-1,onClick:l.wrapEvent(s,(function(){f&&f(i),C("SELECT_WITH_CLICK",{value:i})})),children:u||n.createElement(y,null)})))}));function y(){var e=t.useContext(N).value,a=t.useContext(R).data.value,r=t.useMemo((function(){return s.findAll({searchWords:k(a||"").split(/\s+/),textToHighlight:e})}),[a,e]);return n.createElement(n.Fragment,null,r.length?r.map((function(t,a){var r=e.slice(t.start,t.end);return n.createElement("span",{key:a,"data-user-value":!!t.highlight||void 0,"data-suggested-value":!t.highlight||void 0},r)})):e)}var H=l.forwardRefWithAs((function(e,a){var r=e.as,o=void 0===r?"button":r,u=e.onClick,i=e.onKeyDown,c=p(e,["as","onClick","onKeyDown"]),s=t.useContext(R),v=s.transition,d=s.state,f=s.listboxId,E=s.isExpanded,b=l.useForkedRef(s.buttonRef,a),T=G();return n.createElement(o,Object.assign({"aria-controls":f,"aria-haspopup":"listbox","aria-expanded":E},c,{"data-reach-combobox-button":"",ref:b,onClick:l.wrapEvent(u,(function(){v(d===C?"OPEN_WITH_BUTTON":"CLOSE_WITH_BUTTON")})),onKeyDown:l.wrapEvent(i,T)}))}));function G(){var e=t.useContext(R),n=e.data.navigationValue,a=e.onSelect,r=e.state,o=e.transition,u=e.autocompletePropRef,i=e.persistSelectionRef,l=t.useContext(m).descendants;return function(e){var t=l.findIndex((function(e){return e.value===n}));function c(){return l[0]}function s(){return l[l.length-1]}switch(e.key){case"ArrowDown":if(e.preventDefault(),!l||!l.length)return;if(r===C)o("NAVIGATE",{persistSelection:i.current});else{var v=t===l.length-1?u.current?null:c():l[(t+1)%l.length];o("NAVIGATE",{value:v?v.value:null})}break;case"ArrowUp":if(e.preventDefault(),!l||0===l.length)return;if(r===C)o("NAVIGATE");else{var d=0===t?u.current?null:s():-1===t?s():l[(t-1+l.length)%l.length];o("NAVIGATE",{value:d?d.value:null})}break;case"Home":case"PageUp":if(e.preventDefault(),!l||0===l.length)return;r===C?o("NAVIGATE"):o("NAVIGATE",{value:c().value});break;case"End":case"PageDown":if(e.preventDefault(),!l||0===l.length)return;r===C?o("NAVIGATE"):o("NAVIGATE",{value:s().value});break;case"Escape":r!==C&&o("ESCAPE");break;case"Enter":r===T&&null!==n&&(e.preventDefault(),a&&a(n),o("SELECT_WITH_KEYBOARD"))}}}function V(){var e=t.useContext(R),n=e.state,a=e.transition,r=e.popoverRef,o=e.inputRef,u=e.buttonRef;return function(){var e=l.getOwnerDocument(o.current)||document;requestAnimationFrame((function(){e.activeElement!==o.current&&e.activeElement!==u.current&&r.current&&(r.current.contains(e.activeElement)?n!==x&&a("INTERACT"):a("BLUR"))}))}}var D=function(e){var t=0;if(0===e.length)return t;for(var n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t&=t;return t};function k(e){return String(e).replace(/([.*+?=^!:${}()|[\]/\\])/g,"\\$1")}exports.Combobox=O,exports.ComboboxButton=H,exports.ComboboxInput=S,exports.ComboboxList=_,exports.ComboboxOption=w,exports.ComboboxOptionText=y,exports.ComboboxPopover=L,exports.escapeRegexp=k,exports.useComboboxContext=function(){var e=t.useContext(R),n=e.isExpanded,a=e.comboboxId;return t.useMemo((function(){return{id:a,isExpanded:n}}),[a,n])};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=e(t);require("prop-types");var a,r,o,u,i,l=require("@reach/utils"),c=require("@reach/descendants"),s=require("highlight-words-core"),v=require("@reach/auto-id"),d=require("@reach/popover"),f=e(d);function E(){return(E=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}function p(e,t){if(null==e)return{};var n,a,r={},o=Object.keys(e);for(a=0;a<o.length;a++)t.indexOf(n=o[a])>=0||(r[n]=e[n]);return r}var C="IDLE",b="SUGGESTING",T="NAVIGATING",x="INTERACTING",I={initial:C,states:(i={},i.IDLE={on:(a={},a.BLUR=C,a.CLEAR=C,a.CHANGE=b,a.INITIAL_CHANGE=C,a.FOCUS=b,a.NAVIGATE=T,a.OPEN_WITH_BUTTON=b,a)},i[b]={on:(r={},r.CHANGE=b,r.FOCUS=b,r.NAVIGATE=T,r.CLEAR=C,r.ESCAPE=C,r.BLUR=C,r.SELECT_WITH_CLICK=C,r.INTERACT=x,r.CLOSE_WITH_BUTTON=C,r)},i[T]={on:(o={},o.CHANGE=b,o.FOCUS=b,o.CLEAR=C,o.BLUR=C,o.ESCAPE=C,o.NAVIGATE=T,o.SELECT_WITH_CLICK=C,o.SELECT_WITH_KEYBOARD=C,o.CLOSE_WITH_BUTTON=C,o.INTERACT=x,o)},i[x]={on:(u={},u.CLEAR=C,u.CHANGE=b,u.FOCUS=b,u.BLUR=C,u.ESCAPE=C,u.NAVIGATE=T,u.CLOSE_WITH_BUTTON=C,u.SELECT_WITH_CLICK=C,u)},i)},A=function(e,t){var n=E(E({},e),{},{lastEventType:t.type});switch(t.type){case"CHANGE":case"INITIAL_CHANGE":return E(E({},n),{},{navigationValue:null,value:t.value});case"NAVIGATE":case"OPEN_WITH_BUTTON":return E(E({},n),{},{navigationValue:g(n,t)});case"CLEAR":return E(E({},n),{},{value:"",navigationValue:null});case"BLUR":case"ESCAPE":return E(E({},n),{},{navigationValue:null});case"SELECT_WITH_CLICK":return E(E({},n),{},{value:t.value,navigationValue:null});case"SELECT_WITH_KEYBOARD":return E(E({},n),{},{value:e.navigationValue,navigationValue:null});case"CLOSE_WITH_BUTTON":return E(E({},n),{},{navigationValue:null});case"INTERACT":return n;case"FOCUS":return E(E({},n),{},{navigationValue:g(n,t)});default:return n}};function h(e){return[b,T,x].includes(e)}function g(e,t){return t.value?t.value:t.persistSelection?e.value:null}var m=c.createDescendantContext("ComboboxDescendantContext"),R=l.createNamedContext("ComboboxContext",{}),N=l.createNamedContext("OptionContext",{}),O=l.forwardRefWithAs((function(e,a){var r=e.onSelect,o=e.openOnFocus,u=void 0!==o&&o,i=e.children,s=e.as,d=void 0===s?"div":s,f=e["aria-label"],C=e["aria-labelledby"],b=p(e,["onSelect","openOnFocus","children","as","aria-label","aria-labelledby"]),T=c.useDescendants(),x=T[0],g=T[1],N=t.useRef(),O=t.useRef(),S=t.useRef(),L=t.useRef(),_=t.useRef(),w=function(e,n,a){var r=t.useState(e.initial),o=r[0],u=r[1],i=t.useReducer(n,{value:"",navigationValue:null}),l=i[1];return[o,i[0],function(t,n){void 0===n&&(n={});var a=e.states[o],r=a&&a.on[t];if(r)return l(E({type:t,state:o,nextState:o},n)),void u(r)}]}(I,A),y=w[0],H=w[1],G=w[2];!function(e,t){l.useIsomorphicLayoutEffect((function(){"NAVIGATE"!==e&&"ESCAPE"!==e&&"SELECT_WITH_CLICK"!==e&&"OPEN_WITH_BUTTON"!==e||t.current.focus()}),[t,e])}(H.lastEventType,N);var V=v.useId(b.id),D=V?l.makeId("listbox",V):"listbox",k={ariaLabel:f,ariaLabelledby:C,autocompletePropRef:L,buttonRef:S,comboboxId:V,data:H,inputRef:N,isExpanded:h(y),listboxId:D,onSelect:r||l.noop,openOnFocus:u,persistSelectionRef:_,popoverRef:O,state:y,transition:G};return t.useEffect((function(){return l.checkStyles("combobox")}),[]),n.createElement(c.DescendantProvider,{context:m,items:x,set:g},n.createElement(R.Provider,{value:k},n.createElement(d,Object.assign({},b,{"data-reach-combobox":"",ref:a}),l.isFunction(i)?i({id:V,isExpanded:h(y)}):i)))})),S=l.forwardRefWithAs((function(e,a){var r=e.as,o=void 0===r?"input":r,u=e.selectOnClick,i=void 0!==u&&u,c=e.autocomplete,s=void 0===c||c,v=e.onClick,d=e.onChange,f=e.onKeyDown,E=e.onBlur,C=e.onFocus,b=e.value,I=p(e,["as","selectOnClick","autocomplete","onClick","onChange","onKeyDown","onBlur","onFocus","value"]),A=t.useRef(b).current,h=t.useRef(!1);l.useUpdateEffect((function(){h.current=!0}),[b]);var g=t.useContext(R),m=g.data,N=m.navigationValue,O=m.value,S=m.lastEventType,L=g.inputRef,_=g.state,w=g.transition,y=g.listboxId,H=g.autocompletePropRef,k=g.openOnFocus,W=g.isExpanded,B=g.ariaLabel,U=g.ariaLabelledby,P=l.useForkedRef(L,a),F=t.useRef(!1),K=G(),j=V(),q=null!=b;l.useIsomorphicLayoutEffect((function(){H.current=s}),[s,H]);var M=t.useCallback((function(e){""===e.trim()?w("CLEAR"):w(e!==A||h.current?"CHANGE":"INITIAL_CHANGE",{value:e})}),[A,w]);t.useEffect((function(){!q||b===O||""===b.trim()&&""===(O||"").trim()||M(b)}),[b,M,q,O]);var Y=!s||_!==T&&_!==x?b||O:N||b||O;return n.createElement(o,Object.assign({"aria-activedescendant":N?String(D(N)):void 0,"aria-autocomplete":"both","aria-controls":y,"aria-expanded":W,"aria-haspopup":"listbox","aria-label":B,"aria-labelledby":B?void 0:U,role:"combobox"},I,{"data-reach-combobox-input":"",ref:P,onBlur:l.wrapEvent(E,j),onChange:l.wrapEvent(d,(function(e){q||M(e.target.value)})),onClick:l.wrapEvent(v,(function(){F.current&&(F.current=!1,L.current.select())})),onFocus:l.wrapEvent(C,(function(){i&&(F.current=!0),k&&"SELECT_WITH_CLICK"!==S&&w("FOCUS")})),onKeyDown:l.wrapEvent(f,K),value:Y||""}))})),L=t.forwardRef((function(e,a){var r=e.children,o=e.portal,u=void 0===o||o,i=e.onKeyDown,c=e.onBlur,s=p(e,["children","portal","onKeyDown","onBlur"]),v=t.useContext(R),E=v.inputRef,C=v.isExpanded,b=l.useForkedRef(v.popoverRef,a),T=G(),x=V(),I={"data-reach-combobox-popover":"",onKeyDown:l.wrapEvent(i,T),onBlur:l.wrapEvent(c,x),hidden:!C,tabIndex:-1,children:r};return u?n.createElement(f,Object.assign({},s,{ref:b,position:d.positionMatchWidth,targetRef:E},I)):n.createElement("div",Object.assign({ref:b},s,I))})),_=l.forwardRefWithAs((function(e,a){var r=e.persistSelection,o=void 0!==r&&r,u=e.as,i=void 0===u?"ul":u,l=p(e,["persistSelection","as"]),c=t.useContext(R),s=c.listboxId;return o&&(c.persistSelectionRef.current=!0),n.createElement(i,Object.assign({role:"listbox"},l,{ref:a,"data-reach-combobox-list":"",id:s}))})),w=l.forwardRefWithAs((function(e,a){var r=e.as,o=void 0===r?"li":r,u=e.children,i=e.value,s=e.onClick,v=p(e,["as","children","value","onClick"]),d=t.useContext(R),f=d.onSelect,E=d.data.navigationValue,C=d.transition,b=t.useRef(null),T=l.useForkedRef(a,b),x=c.useDescendant({context:m,element:b.current,value:i}),I=E===i;return n.createElement(N.Provider,{value:{value:i,index:x}},n.createElement(o,Object.assign({"aria-selected":I,role:"option"},v,{"data-reach-combobox-option":"",ref:T,id:String(D(i)),"data-highlighted":I?"":void 0,tabIndex:-1,onClick:l.wrapEvent(s,(function(){f&&f(i),C("SELECT_WITH_CLICK",{value:i})})),children:u||n.createElement(y,null)})))}));function y(){var e=t.useContext(N).value,a=t.useContext(R).data.value,r=t.useMemo((function(){return s.findAll({searchWords:k(a||"").split(/\s+/),textToHighlight:e})}),[a,e]);return n.createElement(n.Fragment,null,r.length?r.map((function(t,a){var r=e.slice(t.start,t.end);return n.createElement("span",{key:a,"data-user-value":!!t.highlight||void 0,"data-suggested-value":!t.highlight||void 0},r)})):e)}var H=l.forwardRefWithAs((function(e,a){var r=e.as,o=void 0===r?"button":r,u=e.onClick,i=e.onKeyDown,c=p(e,["as","onClick","onKeyDown"]),s=t.useContext(R),v=s.transition,d=s.state,f=s.listboxId,E=s.isExpanded,b=l.useForkedRef(s.buttonRef,a),T=G();return n.createElement(o,Object.assign({"aria-controls":f,"aria-haspopup":"listbox","aria-expanded":E},c,{"data-reach-combobox-button":"",ref:b,onClick:l.wrapEvent(u,(function(){v(d===C?"OPEN_WITH_BUTTON":"CLOSE_WITH_BUTTON")})),onKeyDown:l.wrapEvent(i,T)}))}));function G(){var e=t.useContext(R),n=e.data.navigationValue,a=e.onSelect,r=e.state,o=e.transition,u=e.autocompletePropRef,i=e.persistSelectionRef,l=t.useContext(m).descendants;return function(e){var t=l.findIndex((function(e){return e.value===n}));function c(){return l[0]}function s(){return l[l.length-1]}switch(e.key){case"ArrowDown":if(e.preventDefault(),!l||!l.length)return;if(r===C)o("NAVIGATE",{persistSelection:i.current});else{var v=t===l.length-1?u.current?null:c():l[(t+1)%l.length];o("NAVIGATE",{value:v?v.value:null})}break;case"ArrowUp":if(e.preventDefault(),!l||0===l.length)return;if(r===C)o("NAVIGATE");else{var d=0===t?u.current?null:s():-1===t?s():l[(t-1+l.length)%l.length];o("NAVIGATE",{value:d?d.value:null})}break;case"Home":case"PageUp":if(e.preventDefault(),!l||0===l.length)return;r===C?o("NAVIGATE"):o("NAVIGATE",{value:c().value});break;case"End":case"PageDown":if(e.preventDefault(),!l||0===l.length)return;r===C?o("NAVIGATE"):o("NAVIGATE",{value:s().value});break;case"Escape":r!==C&&o("ESCAPE");break;case"Enter":r===T&&null!==n&&(e.preventDefault(),a&&a(n),o("SELECT_WITH_KEYBOARD"))}}}function V(){var e=t.useContext(R),n=e.state,a=e.transition,r=e.popoverRef,o=e.inputRef,u=e.buttonRef;return function(){var e=l.getOwnerDocument(o.current)||document;requestAnimationFrame((function(){e.activeElement!==o.current&&e.activeElement!==u.current&&r.current&&(r.current.contains(e.activeElement)?n!==x&&a("INTERACT"):a("BLUR"))}))}}var D=function(e){var t=0;if(0===e.length)return t;for(var n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t&=t;return t};function k(e){return String(e).replace(/([.*+?=^!:${}()|[\]/\\])/g,"\\$1")}exports.Combobox=O,exports.ComboboxButton=H,exports.ComboboxInput=S,exports.ComboboxList=_,exports.ComboboxOption=w,exports.ComboboxOptionText=y,exports.ComboboxPopover=L,exports.escapeRegexp=k,exports.useComboboxContext=function(){var e=t.useContext(R),n=e.isExpanded,a=e.comboboxId;return t.useMemo((function(){return{id:a,isExpanded:n}}),[a,n])};
//# sourceMappingURL=combobox.cjs.production.min.js.map

@@ -93,3 +93,3 @@ import React, { useRef, useEffect, useContext, useCallback, forwardRef, useMemo, useState, useReducer } from 'react';

var reducer = function reducer(data, event) {
var nextState = _extends({}, data, {
var nextState = _extends(_extends({}, data), {}, {
lastEventType: event.type

@@ -101,3 +101,3 @@ });

case INITIAL_CHANGE:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: null,

@@ -109,3 +109,3 @@ value: event.value

case OPEN_WITH_BUTTON:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: findNavigationValue(nextState, event)

@@ -115,3 +115,3 @@ });

case CLEAR:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
value: "",

@@ -123,3 +123,3 @@ navigationValue: null

case ESCAPE:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: null

@@ -129,3 +129,3 @@ });

case SELECT_WITH_CLICK:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
value: event.value,

@@ -136,3 +136,3 @@ navigationValue: null

case SELECT_WITH_KEYBOARD:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
value: data.navigationValue,

@@ -143,3 +143,3 @@ navigationValue: null

case CLOSE_WITH_BUTTON:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: null

@@ -152,3 +152,3 @@ });

case FOCUS:
return _extends({}, nextState, {
return _extends(_extends({}, nextState), {}, {
navigationValue: findNavigationValue(nextState, event)

@@ -155,0 +155,0 @@ });

{
"name": "@reach/combobox",
"version": "0.10.1",
"version": "0.10.2",
"description": "Accessible React Combobox (Autocomplete).",

@@ -16,10 +16,10 @@ "author": "React Training <hello@reacttraining.com>",

"dependencies": {
"@reach/auto-id": "^0.10.1",
"@reach/descendants": "^0.10.1",
"@reach/popover": "^0.10.1",
"@reach/portal": "^0.10.1",
"@reach/utils": "^0.10.1",
"@reach/auto-id": "^0.10.2",
"@reach/descendants": "^0.10.2",
"@reach/popover": "^0.10.2",
"@reach/portal": "^0.10.2",
"@reach/utils": "^0.10.2",
"highlight-words-core": "1.2.2",
"prop-types": "^15.7.2",
"tslib": "^1.11.1"
"tslib": "^1.11.2"
},

@@ -38,3 +38,3 @@ "peerDependencies": {

],
"gitHead": "c279bc0fb9ae84aa77306c5f1a9909d088bc665c"
"gitHead": "9e4b9adab7fd3085b1fb4b54882a2231308b7416"
}

Sorry, the diff of this file is not supported yet

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