@blueprintjs/select
Advanced tools
Comparing version 3.2.1 to 3.3.0
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@blueprintjs/core"),require("tslib"),require("react"),require("classnames")):"function"==typeof define&&define.amd?define(["@blueprintjs/core","tslib","react","classnames"],t):"object"==typeof exports?exports.Select=t(require("@blueprintjs/core"),require("tslib"),require("react"),require("classnames")):(e.Blueprint=e.Blueprint||{},e.Blueprint.Select=t(e.Blueprint.Core,e.tslib,e.React,e.classNames))}("undefined"!=typeof self?self:this,function(e,t,n,r){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t){e.exports=n},function(e,t){e.exports=r},function(e,t,n){e.exports=n(5)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};n.d(r,"MULTISELECT",function(){return i}),n.d(r,"MULTISELECT_POPOVER",function(){return p}),n.d(r,"OMNIBAR",function(){return a}),n.d(r,"OMNIBAR_OVERLAY",function(){return l}),n.d(r,"SELECT",function(){return u}),n.d(r,"SELECT_POPOVER",function(){return c});var o=n(0),s=o.Classes.getClassNamespace(),i=s+"-multi-select",p=i+"-popover",a=s+"-omnibar",l=a+"-overlay",u=s+"-select",c=u+"-popover";function d(e,t,n){if(0===e.query.length&&void 0!==n)return n;var r=e.filteredItems.map(e.renderItem).filter(function(e){return null!=e});return r.length>0?r:t}var v=n(1),f=n(3),m=n.n(f),h=n(2),y=function(e){function t(t,n){var r=e.call(this,t,n)||this;r.refHandlers={itemsParent:function(e){return r.itemsParentRef=e}},r.shouldCheckActiveItemInViewport=!1,r.renderItemList=function(e){var t=r.props,n=t.initialContent,s=d(e,t.noResults,n);return h.createElement(o.Menu,{ulRef:e.itemsParentRef},s)},r.renderItem=function(e,t){var n=r.state,o=n.activeItem,s=n.query,i=r.state.filteredItems.indexOf(e)>=0,p={active:o===e,disabled:O(e,t,r.props.itemDisabled),matchesPredicate:i};return r.props.itemRenderer(e,{handleClick:function(t){return r.handleItemSelect(e,t)},index:t,modifiers:p,query:s})},r.handleItemSelect=function(e,t){r.setActiveItem(e),o.Utils.safeInvoke(r.props.onItemSelect,e,t),r.props.resetOnSelect&&r.setQuery("",!0)},r.handleKeyDown=function(e){var t=e.keyCode;if(t===o.Keys.ARROW_UP||t===o.Keys.ARROW_DOWN){e.preventDefault();var n=r.getNextActiveItem(t===o.Keys.ARROW_UP?-1:1);null!=n&&r.setActiveItem(n)}o.Utils.safeInvoke(r.props.onKeyDown,e)},r.handleKeyUp=function(e){var t=r.props.onKeyUp,n=r.state.activeItem;e.keyCode===o.Keys.ENTER&&null!=n&&(e.preventDefault(),r.handleItemSelect(n,e)),o.Utils.safeInvoke(t,e)},r.handleQueryChange=function(e){var t=null==e?"":e.target.value;r.setQuery(t),o.Utils.safeInvoke(r.props.onQueryChange,t,e)};var s=r.props.query,i=void 0===s?"":s,p=P(i,r.props);return r.state={activeItem:g(p,r.props.itemDisabled),filteredItems:p,query:i},r}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=e.className,n=e.items,r=e.renderer,o=e.itemListRenderer,s=void 0===o?this.renderItemList:o;return r(v.__assign({},this.state,{className:t,handleItemSelect:this.handleItemSelect,handleKeyDown:this.handleKeyDown,handleKeyUp:this.handleKeyUp,handleQueryChange:this.handleQueryChange,itemList:s(v.__assign({},this.state,{items:n,itemsParentRef:this.refHandlers.itemsParent,renderItem:this.renderItem}))}))},t.prototype.componentWillReceiveProps=function(e){void 0!==e.activeItem&&(this.shouldCheckActiveItemInViewport=!0,this.setState({activeItem:e.activeItem})),null!=e.query&&this.setQuery(e.query)},t.prototype.componentDidUpdate=function(e){var t=this;o.Utils.shallowCompareKeys(this.props,e,{include:["items","itemListPredicate","itemPredicate"]})||this.setQuery(this.state.query),this.shouldCheckActiveItemInViewport&&(requestAnimationFrame(function(){return t.scrollActiveItemIntoView()}),this.shouldCheckActiveItemInViewport=!1)},t.prototype.scrollActiveItemIntoView=function(){var e=this.getActiveElement();if(null!=this.itemsParentRef&&null!=e){var t=e.offsetTop,n=e.offsetHeight,r=this.itemsParentRef,o=r.offsetTop,s=r.scrollTop,i=r.clientHeight,p=this.getItemsParentPadding(),a=p.paddingTop,l=t+n+p.paddingBottom-o,u=t-a-o;l>=s+i?this.itemsParentRef.scrollTop=l+n-i:u<=s&&(this.itemsParentRef.scrollTop=u-n)}},t.prototype.setQuery=function(e,t){void 0===t&&(t=this.props.resetOnQuery),this.shouldCheckActiveItemInViewport=!0;var n=e!==this.state.query;n&&o.Utils.safeInvoke(this.props.onQueryChange,e);var r=P(e,this.props);this.setState({filteredItems:r,query:e});var s=this.getActiveIndex(r),i=t||s<0||O(this.state.activeItem,s,this.props.itemDisabled);n&&i&&this.setActiveItem(g(r,this.props.itemDisabled))},t.prototype.getActiveElement=function(){if(null!=this.itemsParentRef)return this.itemsParentRef.children.item(this.getActiveIndex())},t.prototype.getActiveIndex=function(e){void 0===e&&(e=this.state.filteredItems);var t=this.state.activeItem;return null==t?-1:e.indexOf(t)},t.prototype.getItemsParentPadding=function(){var e=getComputedStyle(this.itemsParentRef),t=e.paddingTop;return{paddingBottom:I(e.paddingBottom),paddingTop:I(t)}},t.prototype.getNextActiveItem=function(e,t){return void 0===t&&(t=this.getActiveIndex()),g(this.state.filteredItems,this.props.itemDisabled,e,t)},t.prototype.setActiveItem=function(e){void 0===this.props.activeItem&&(this.shouldCheckActiveItemInViewport=!0,this.setState({activeItem:e})),o.Utils.safeInvoke(this.props.onActiveItemChange,e)},t.displayName=o.DISPLAYNAME_PREFIX+".QueryList",t.defaultProps={resetOnQuery:!0},t}(h.Component);function I(e){return null==e?0:parseInt(e.slice(0,-2),10)}function P(e,t){var n=t.items,r=t.itemPredicate,s=t.itemListPredicate;return o.Utils.isFunction(s)?s(e,n):o.Utils.isFunction(r)?n.filter(function(t,n){return r(e,t,n)}):n}function O(e,t,n){return null!=n&&null!=e&&(o.Utils.isFunction(n)?n(e,t):!!e[n])}function g(e,t,n,r){if(void 0===n&&(n=1),void 0===r&&(r=e.length-1),0===e.length)return null;var o,s,i,p=r,a=e.length-1;do{if(i=a,!O(e[p=(o=p+n)<(s=0)?i:o>i?s:o],p,t))return e[p]}while(p!==r);return null}var E=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.TypedQueryList=y.ofType(),t.refHandlers={queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,s=n.inputProps,i=void 0===s?{}:s,p=n.isOpen,a=n.overlayProps,l=void 0===a?{}:a,u=e.handleKeyDown,c=e.handleKeyUp,d=p&&e.query.length>0?{onKeyDown:u,onKeyUp:c}:{};return h.createElement(o.Overlay,v.__assign({hasBackdrop:!0},l,{isOpen:p,className:m()(r.OMNIBAR_OVERLAY,l.className),onClose:t.handleOverlayClose}),h.createElement("div",v.__assign({className:m()(r.OMNIBAR,e.className)},d),h.createElement(o.InputGroup,v.__assign({autoFocus:!0,large:!0,leftIcon:"search",placeholder:"Search..."},i,{onChange:e.handleQueryChange,value:e.query})),e.itemList))},t.handleOverlayClose=function(e){var n=t.props.overlayProps,r=void 0===n?{}:n;o.Utils.safeInvoke(r.onClose,e),o.Utils.safeInvoke(t.props.onClose,e)},t}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=e.initialContent,n=void 0===t?null:t,r=(e.isOpen,e.inputProps,e.overlayProps,v.__rest(e,["initialContent","isOpen","inputProps","overlayProps"]));return h.createElement(this.TypedQueryList,v.__assign({},r,{initialContent:n,onItemSelect:this.props.onItemSelect,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.displayName=o.DISPLAYNAME_PREFIX+".Omnibar",t}(h.PureComponent),C=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={isOpen:t.props.popoverProps&&t.props.popoverProps.isOpen||!1},t.TypedQueryList=y.ofType(),t.refHandlers={input:function(e){t.input=e;var n=t.props.tagInputProps,r=void 0===n?{}:n;o.Utils.safeInvoke(r.inputRef,e)},queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,s=n.tagInputProps,i=void 0===s?{}:s,p=n.popoverProps,a=void 0===p?{}:p,l=n.selectedItems,u=void 0===l?[]:l,c=n.placeholder,d=e.handleKeyDown,f=e.handleKeyUp;return h.createElement(o.Popover,v.__assign({autoFocus:!1,canEscapeKeyClose:!0,enforceFocus:!1,isOpen:t.state.isOpen,position:o.Position.BOTTOM_LEFT},a,{className:m()(e.className,a.className),onInteraction:t.handlePopoverInteraction,popoverClassName:m()(r.MULTISELECT_POPOVER,a.popoverClassName),onOpened:t.handlePopoverOpened}),h.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(d),onKeyUp:t.state.isOpen?f:void 0},h.createElement(o.TagInput,v.__assign({placeholder:c},i,{className:m()(r.MULTISELECT,i.className),inputRef:t.refHandlers.input,inputValue:e.query,onInputChange:e.handleQueryChange,values:u.map(t.props.tagRenderer)}))),h.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(d),onKeyUp:f},e.itemList))},t.handleItemSelect=function(e,n){null!=t.input&&t.input.focus(),o.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handleQueryChange=function(e,n){t.setState({isOpen:e.length>0||!t.props.openOnKeyDown}),o.Utils.safeInvoke(t.props.onQueryChange,e,n)},t.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var n=t.props.popoverProps,r=void 0===n?{}:n;null!=t.input&&t.input!==document.activeElement?t.setState({isOpen:!1}):t.props.openOnKeyDown||t.setState({isOpen:!0}),o.Utils.safeInvoke(r.onInteraction,e)})},t.handlePopoverOpened=function(e){var n=t.props.popoverProps,r=void 0===n?{}:n;null!=t.queryList&&t.queryList.scrollActiveItemIntoView(),o.Utils.safeInvoke(r.onOpened,e)},t.getTargetKeyDownHandler=function(e){return function(n){var r=n.which;r===o.Keys.ESCAPE||r===o.Keys.TAB?(null!=t.input&&t.input.blur(),t.setState({isOpen:!1})):r!==o.Keys.BACKSPACE&&r!==o.Keys.ARROW_LEFT&&r!==o.Keys.ARROW_RIGHT&&t.setState({isOpen:!0}),t.state.isOpen&&o.Utils.safeInvoke(e,n)}},t}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.openOnKeyDown,e.popoverProps,e.tagInputProps,v.__rest(e,["openOnKeyDown","popoverProps","tagInputProps"]));return h.createElement(this.TypedQueryList,v.__assign({},t,{onItemSelect:this.handleItemSelect,onQueryChange:this.handleQueryChange,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.displayName=o.DISPLAYNAME_PREFIX+".MultiSelect",t.defaultProps={placeholder:"Search..."},t}(h.PureComponent),_=function(e){function t(t,n){var s=e.call(this,t,n)||this;return s.TypedQueryList=y.ofType(),s.refHandlers={input:function(e){s.input=e;var t=s.props.inputProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.inputRef,e)},queryList:function(e){return s.list=e}},s.renderQueryList=function(e){var t=s.props,n=t.filterable,i=void 0===n||n,p=t.disabled,a=void 0!==p&&p,l=t.inputProps,u=void 0===l?{}:l,c=t.popoverProps,d=void 0===c?{}:c,f=h.createElement(o.InputGroup,v.__assign({leftIcon:"search",placeholder:"Filter...",rightElement:s.maybeRenderClearButton(e.query)},u,{inputRef:s.refHandlers.input,onChange:e.handleQueryChange,value:e.query})),y=e.handleKeyDown,I=e.handleKeyUp;return h.createElement(o.Popover,v.__assign({autoFocus:!1,enforceFocus:!1,isOpen:s.state.isOpen,disabled:a,position:o.Position.BOTTOM_LEFT},d,{className:m()(e.className,d.className),onInteraction:s.handlePopoverInteraction,popoverClassName:m()(r.SELECT_POPOVER,d.popoverClassName),onOpening:s.handlePopoverOpening,onOpened:s.handlePopoverOpened,onClosing:s.handlePopoverClosing}),h.createElement("div",{onKeyDown:s.state.isOpen?y:s.handleTargetKeyDown,onKeyUp:s.state.isOpen?I:void 0},s.props.children),h.createElement("div",{onKeyDown:y,onKeyUp:I},i?f:void 0,e.itemList))},s.handleTargetKeyDown=function(e){e.which!==o.Keys.ARROW_UP&&e.which!==o.Keys.ARROW_DOWN||(e.preventDefault(),s.setState({isOpen:!0}))},s.handleItemSelect=function(e,t){s.setState({isOpen:!1}),o.Utils.safeInvoke(s.props.onItemSelect,e,t)},s.handlePopoverInteraction=function(e){s.setState({isOpen:e});var t=s.props.popoverProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.onInteraction,e)},s.handlePopoverOpening=function(e){var t=s.props,n=t.popoverProps,r=void 0===n?{}:n,i=t.resetOnClose;s.previousFocusedElement=document.activeElement,i&&s.resetQuery(),o.Utils.safeInvoke(r.onOpening,e)},s.handlePopoverOpened=function(e){null!=s.list&&s.list.scrollActiveItemIntoView(),requestAnimationFrame(function(){var e=s.props.inputProps;!1!==(void 0===e?{}:e).autoFocus&&null!=s.input&&s.input.focus()});var t=s.props.popoverProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.onOpened,e)},s.handlePopoverClosing=function(e){requestAnimationFrame(function(){void 0!==s.previousFocusedElement&&(s.previousFocusedElement.focus(),s.previousFocusedElement=void 0)});var t=s.props.popoverProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.onClosing,e)},s.resetQuery=function(){return s.list&&s.list.setQuery("",!0)},s.state={isOpen:!1},s}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.filterable,e.inputProps,e.popoverProps,v.__rest(e,["filterable","inputProps","popoverProps"]));return h.createElement(this.TypedQueryList,v.__assign({},t,{onItemSelect:this.handleItemSelect,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.list&&this.list.scrollActiveItemIntoView()},t.prototype.maybeRenderClearButton=function(e){return e.length>0?h.createElement(o.Button,{icon:"cross",minimal:!0,onClick:this.resetQuery}):void 0},t.displayName=o.DISPLAYNAME_PREFIX+".Select",t}(h.PureComponent),S=function(e){function t(t,n){var s=e.call(this,t,n)||this;return s.TypedQueryList=y.ofType(),s.refHandlers={input:function(e){s.input=e;var t=s.props.inputProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.inputRef,e)},queryList:function(e){return s.queryList=e}},s.renderQueryList=function(e){var t=s.props,n=t.inputProps,i=void 0===n?{}:n,p=t.popoverProps,a=void 0===p?{}:p,l=s.state,u=l.isOpen,c=l.selectedItem,d=e.handleKeyDown,f=e.handleKeyUp,y=i.placeholder,I=void 0===y?"Search...":y,P=c?s.props.inputValueRenderer(c):"";return h.createElement(o.Popover,v.__assign({autoFocus:!1,enforceFocus:!1,isOpen:u,position:o.Position.BOTTOM_LEFT},a,{className:m()(e.className,a.className),onInteraction:s.handlePopoverInteraction,popoverClassName:m()(r.SELECT_POPOVER,a.popoverClassName),onOpened:s.handlePopoverOpened}),h.createElement(o.InputGroup,v.__assign({},i,{placeholder:u&&P?P:I,inputRef:s.refHandlers.input,onChange:e.handleQueryChange,onFocus:s.handleInputFocus,onKeyDown:s.getTargetKeyDownHandler(d),onKeyUp:s.getTargetKeyUpHandler(f),value:u?e.query:P})),h.createElement("div",{onKeyDown:d,onKeyUp:f},e.itemList))},s.selectText=function(){requestAnimationFrame(function(){null!=s.input&&s.input.setSelectionRange(0,s.input.value.length)})},s.handleInputFocus=function(e){var t=s.props,n=t.openOnKeyDown,r=t.inputProps,i=void 0===r?{}:r;s.selectText(),n||s.setState({isOpen:!0}),o.Utils.safeInvoke(i.onFocus,e)},s.handleItemSelect=function(e,t){var n;s.props.closeOnSelect?(null!=s.input&&s.input.blur(),n=!1):(null!=s.input&&s.input.focus(),s.selectText(),n=!0),void 0===s.props.selectedItem?s.setState({isOpen:n,selectedItem:e}):s.setState({isOpen:n}),o.Utils.safeInvoke(s.props.onItemSelect,e,t)},s.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var t=s.props.popoverProps,n=void 0===t?{}:t;null!=s.input&&s.input!==document.activeElement&&s.setState({isOpen:!1}),o.Utils.safeInvoke(n.onInteraction,e)})},s.handlePopoverOpened=function(e){var t=s.props.popoverProps,n=void 0===t?{}:t;null!=s.queryList&&s.queryList.scrollActiveItemIntoView(),o.Utils.safeInvoke(n.onOpened,e)},s.getTargetKeyDownHandler=function(e){return function(t){var n=t.which,r=s.props,i=r.inputProps,p=void 0===i?{}:i,a=r.openOnKeyDown;n===o.Keys.ESCAPE||n===o.Keys.TAB?(null!=s.input&&s.input.blur(),s.setState({isOpen:!1})):a&&n!==o.Keys.BACKSPACE&&n!==o.Keys.ARROW_LEFT&&n!==o.Keys.ARROW_RIGHT&&s.setState({isOpen:!0}),s.state.isOpen&&o.Utils.safeInvoke(e,t),o.Utils.safeInvoke(p.onKeyDown,t)}},s.getTargetKeyUpHandler=function(e){return function(t){var n=s.props.inputProps,r=void 0===n?{}:n;s.state.isOpen&&o.Utils.safeInvoke(e,t),o.Utils.safeInvoke(r.onKeyUp,t)}},s.state={isOpen:t.popoverProps&&t.popoverProps.isOpen||!1,selectedItem:s.getInitialSelectedItem()},s}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.inputProps,e.popoverProps,v.__rest(e,["inputProps","popoverProps"]));return h.createElement(this.TypedQueryList,v.__assign({},t,{onItemSelect:this.handleItemSelect,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentWillReceiveProps=function(e){void 0!==e.selectedItem&&e.selectedItem!==this.state.selectedItem&&this.setState({selectedItem:e.selectedItem})},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.queryList&&this.queryList.scrollActiveItemIntoView()},t.prototype.getInitialSelectedItem=function(){return void 0!==this.props.selectedItem?this.props.selectedItem:void 0!==this.props.defaultSelectedItem?this.props.defaultSelectedItem:null},t.displayName=o.DISPLAYNAME_PREFIX+".Suggest",t.defaultProps={closeOnSelect:!0,openOnKeyDown:!1},t}(h.PureComponent);n.d(t,"Classes",function(){return r}),n.d(t,"renderFilteredItems",function(){return d}),n.d(t,"Omnibar",function(){return E}),n.d(t,"QueryList",function(){return y}),n.d(t,"getFirstEnabledItem",function(){return g}),n.d(t,"MultiSelect",function(){return C}),n.d(t,"Select",function(){return _}),n.d(t,"Suggest",function(){return S})}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@blueprintjs/core"),require("tslib"),require("react"),require("classnames")):"function"==typeof define&&define.amd?define(["@blueprintjs/core","tslib","react","classnames"],t):"object"==typeof exports?exports.Select=t(require("@blueprintjs/core"),require("tslib"),require("react"),require("classnames")):(e.Blueprint=e.Blueprint||{},e.Blueprint.Select=t(e.Blueprint.Core,e.tslib,e.React,e.classNames))}("undefined"!=typeof self?self:this,function(e,t,n,r){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t){e.exports=n},function(e,t){e.exports=r},function(e,t,n){e.exports=n(5)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};n.d(r,"MULTISELECT",function(){return i}),n.d(r,"MULTISELECT_POPOVER",function(){return p}),n.d(r,"OMNIBAR",function(){return a}),n.d(r,"OMNIBAR_OVERLAY",function(){return l}),n.d(r,"SELECT",function(){return u}),n.d(r,"SELECT_POPOVER",function(){return c});var o=n(0),s=o.Classes.getClassNamespace(),i=s+"-multi-select",p=i+"-popover",a=s+"-omnibar",l=a+"-overlay",u=s+"-select",c=u+"-popover";function d(e,t,n){if(0===e.query.length&&void 0!==n)return n;var r=e.filteredItems.map(e.renderItem).filter(function(e){return null!=e});return r.length>0?r:t}var v=n(1),f=n(3),m=n.n(f),h=n(2),y=function(e){function t(t,n){var r=e.call(this,t,n)||this;r.refHandlers={itemsParent:function(e){return r.itemsParentRef=e}},r.shouldCheckActiveItemInViewport=!1,r.expectedNextActiveItem=null,r.renderItemList=function(e){var t=r.props,n=t.initialContent,s=d(e,t.noResults,n);return h.createElement(o.Menu,{ulRef:e.itemsParentRef},s)},r.renderItem=function(e,t){var n=r.state,o=n.activeItem,s=n.query,i=r.state.filteredItems.indexOf(e)>=0,p={active:o===e,disabled:O(e,t,r.props.itemDisabled),matchesPredicate:i};return r.props.itemRenderer(e,{handleClick:function(t){return r.handleItemSelect(e,t)},index:t,modifiers:p,query:s})},r.handleItemSelect=function(e,t){r.setActiveItem(e),o.Utils.safeInvoke(r.props.onItemSelect,e,t),r.props.resetOnSelect&&r.setQuery("",!0)},r.handleKeyDown=function(e){var t=e.keyCode;if(t===o.Keys.ARROW_UP||t===o.Keys.ARROW_DOWN){e.preventDefault();var n=r.getNextActiveItem(t===o.Keys.ARROW_UP?-1:1);null!=n&&r.setActiveItem(n)}o.Utils.safeInvoke(r.props.onKeyDown,e)},r.handleKeyUp=function(e){var t=r.props.onKeyUp,n=r.state.activeItem;e.keyCode===o.Keys.ENTER&&null!=n&&(e.preventDefault(),r.handleItemSelect(n,e)),o.Utils.safeInvoke(t,e)},r.handleQueryChange=function(e){var t=null==e?"":e.target.value;r.setQuery(t),o.Utils.safeInvoke(r.props.onQueryChange,t,e)};var s=r.props.query,i=void 0===s?"":s,p=P(i,r.props);return r.state={activeItem:g(p,r.props.itemDisabled),filteredItems:p,query:i},r}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=e.className,n=e.items,r=e.renderer,o=e.itemListRenderer,s=void 0===o?this.renderItemList:o;return r(v.__assign({},this.state,{className:t,handleItemSelect:this.handleItemSelect,handleKeyDown:this.handleKeyDown,handleKeyUp:this.handleKeyUp,handleQueryChange:this.handleQueryChange,itemList:s(v.__assign({},this.state,{items:n,itemsParentRef:this.refHandlers.itemsParent,renderItem:this.renderItem}))}))},t.prototype.componentWillReceiveProps=function(e){void 0!==e.activeItem&&(this.shouldCheckActiveItemInViewport=!0,this.setState({activeItem:e.activeItem})),null!=e.query&&this.setQuery(e.query)},t.prototype.componentDidUpdate=function(e){var t=this;o.Utils.shallowCompareKeys(this.props,e,{include:["items","itemListPredicate","itemPredicate"]})||this.setQuery(this.state.query),this.shouldCheckActiveItemInViewport&&(requestAnimationFrame(function(){return t.scrollActiveItemIntoView()}),this.shouldCheckActiveItemInViewport=!1)},t.prototype.scrollActiveItemIntoView=function(){var e=!1!==this.props.scrollToActiveItem,t=this.expectedNextActiveItem!==this.props.activeItem;if(this.expectedNextActiveItem=null,e||!t){var n=this.getActiveElement();if(null!=this.itemsParentRef&&null!=n){var r=n.offsetTop,o=n.offsetHeight,s=this.itemsParentRef,i=s.offsetTop,p=s.scrollTop,a=s.clientHeight,l=this.getItemsParentPadding(),u=l.paddingTop,c=r+o+l.paddingBottom-i,d=r-u-i;c>=p+a?this.itemsParentRef.scrollTop=c+o-a:d<=p&&(this.itemsParentRef.scrollTop=d-o)}}},t.prototype.setQuery=function(e,t){void 0===t&&(t=this.props.resetOnQuery),this.shouldCheckActiveItemInViewport=!0;var n=e!==this.state.query;n&&o.Utils.safeInvoke(this.props.onQueryChange,e);var r=P(e,this.props);this.setState({filteredItems:r,query:e});var s=this.getActiveIndex(r),i=t||s<0||O(this.state.activeItem,s,this.props.itemDisabled);n&&i&&this.setActiveItem(g(r,this.props.itemDisabled))},t.prototype.getActiveElement=function(){if(null!=this.itemsParentRef)return this.itemsParentRef.children.item(this.getActiveIndex())},t.prototype.getActiveIndex=function(e){void 0===e&&(e=this.state.filteredItems);var t=this.state.activeItem;return null==t?-1:e.indexOf(t)},t.prototype.getItemsParentPadding=function(){var e=getComputedStyle(this.itemsParentRef),t=e.paddingTop;return{paddingBottom:I(e.paddingBottom),paddingTop:I(t)}},t.prototype.getNextActiveItem=function(e,t){return void 0===t&&(t=this.getActiveIndex()),g(this.state.filteredItems,this.props.itemDisabled,e,t)},t.prototype.setActiveItem=function(e){this.expectedNextActiveItem=e,void 0===this.props.activeItem&&(this.shouldCheckActiveItemInViewport=!0,this.setState({activeItem:e})),o.Utils.safeInvoke(this.props.onActiveItemChange,e)},t.displayName=o.DISPLAYNAME_PREFIX+".QueryList",t.defaultProps={resetOnQuery:!0},t}(h.Component);function I(e){return null==e?0:parseInt(e.slice(0,-2),10)}function P(e,t){var n=t.items,r=t.itemPredicate,s=t.itemListPredicate;return o.Utils.isFunction(s)?s(e,n):o.Utils.isFunction(r)?n.filter(function(t,n){return r(e,t,n)}):n}function O(e,t,n){return null!=n&&null!=e&&(o.Utils.isFunction(n)?n(e,t):!!e[n])}function g(e,t,n,r){if(void 0===n&&(n=1),void 0===r&&(r=e.length-1),0===e.length)return null;var o,s,i,p=r,a=e.length-1;do{if(i=a,!O(e[p=(o=p+n)<(s=0)?i:o>i?s:o],p,t))return e[p]}while(p!==r);return null}var E=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.TypedQueryList=y.ofType(),t.refHandlers={queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,s=n.inputProps,i=void 0===s?{}:s,p=n.isOpen,a=n.overlayProps,l=void 0===a?{}:a,u=e.handleKeyDown,c=e.handleKeyUp,d=p?{onKeyDown:u,onKeyUp:c}:{};return h.createElement(o.Overlay,v.__assign({hasBackdrop:!0},l,{isOpen:p,className:m()(r.OMNIBAR_OVERLAY,l.className),onClose:t.handleOverlayClose}),h.createElement("div",v.__assign({className:m()(r.OMNIBAR,e.className)},d),h.createElement(o.InputGroup,v.__assign({autoFocus:!0,large:!0,leftIcon:"search",placeholder:"Search..."},i,{onChange:e.handleQueryChange,value:e.query})),e.itemList))},t.handleOverlayClose=function(e){var n=t.props.overlayProps,r=void 0===n?{}:n;o.Utils.safeInvoke(r.onClose,e),o.Utils.safeInvoke(t.props.onClose,e)},t}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=e.initialContent,n=void 0===t?null:t,r=(e.isOpen,e.inputProps,e.overlayProps,v.__rest(e,["initialContent","isOpen","inputProps","overlayProps"]));return h.createElement(this.TypedQueryList,v.__assign({},r,{initialContent:n,onItemSelect:this.props.onItemSelect,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.displayName=o.DISPLAYNAME_PREFIX+".Omnibar",t}(h.PureComponent),C=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={isOpen:t.props.popoverProps&&t.props.popoverProps.isOpen||!1},t.TypedQueryList=y.ofType(),t.refHandlers={input:function(e){t.input=e;var n=t.props.tagInputProps,r=void 0===n?{}:n;o.Utils.safeInvoke(r.inputRef,e)},queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,s=n.tagInputProps,i=void 0===s?{}:s,p=n.popoverProps,a=void 0===p?{}:p,l=n.selectedItems,u=void 0===l?[]:l,c=n.placeholder,d=e.handleKeyDown,f=e.handleKeyUp;return h.createElement(o.Popover,v.__assign({autoFocus:!1,canEscapeKeyClose:!0,enforceFocus:!1,isOpen:t.state.isOpen,position:o.Position.BOTTOM_LEFT},a,{className:m()(e.className,a.className),onInteraction:t.handlePopoverInteraction,popoverClassName:m()(r.MULTISELECT_POPOVER,a.popoverClassName),onOpened:t.handlePopoverOpened}),h.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(d),onKeyUp:t.state.isOpen?f:void 0},h.createElement(o.TagInput,v.__assign({placeholder:c},i,{className:m()(r.MULTISELECT,i.className),inputRef:t.refHandlers.input,inputValue:e.query,onInputChange:e.handleQueryChange,values:u.map(t.props.tagRenderer)}))),h.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(d),onKeyUp:f},e.itemList))},t.handleItemSelect=function(e,n){null!=t.input&&t.input.focus(),o.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handleQueryChange=function(e,n){t.setState({isOpen:e.length>0||!t.props.openOnKeyDown}),o.Utils.safeInvoke(t.props.onQueryChange,e,n)},t.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var n=t.props.popoverProps,r=void 0===n?{}:n;null!=t.input&&t.input!==document.activeElement?t.setState({isOpen:!1}):t.props.openOnKeyDown||t.setState({isOpen:!0}),o.Utils.safeInvoke(r.onInteraction,e)})},t.handlePopoverOpened=function(e){var n=t.props.popoverProps,r=void 0===n?{}:n;null!=t.queryList&&t.queryList.scrollActiveItemIntoView(),o.Utils.safeInvoke(r.onOpened,e)},t.getTargetKeyDownHandler=function(e){return function(n){var r=n.which;r===o.Keys.ESCAPE||r===o.Keys.TAB?(null!=t.input&&t.input.blur(),t.setState({isOpen:!1})):r!==o.Keys.BACKSPACE&&r!==o.Keys.ARROW_LEFT&&r!==o.Keys.ARROW_RIGHT&&t.setState({isOpen:!0}),t.state.isOpen&&o.Utils.safeInvoke(e,n)}},t}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.openOnKeyDown,e.popoverProps,e.tagInputProps,v.__rest(e,["openOnKeyDown","popoverProps","tagInputProps"]));return h.createElement(this.TypedQueryList,v.__assign({},t,{onItemSelect:this.handleItemSelect,onQueryChange:this.handleQueryChange,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.displayName=o.DISPLAYNAME_PREFIX+".MultiSelect",t.defaultProps={placeholder:"Search..."},t}(h.PureComponent),_=function(e){function t(t,n){var s=e.call(this,t,n)||this;return s.TypedQueryList=y.ofType(),s.refHandlers={input:function(e){s.input=e;var t=s.props.inputProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.inputRef,e)},queryList:function(e){return s.list=e}},s.renderQueryList=function(e){var t=s.props,n=t.filterable,i=void 0===n||n,p=t.disabled,a=void 0!==p&&p,l=t.inputProps,u=void 0===l?{}:l,c=t.popoverProps,d=void 0===c?{}:c,f=h.createElement(o.InputGroup,v.__assign({leftIcon:"search",placeholder:"Filter...",rightElement:s.maybeRenderClearButton(e.query)},u,{inputRef:s.refHandlers.input,onChange:e.handleQueryChange,value:e.query})),y=e.handleKeyDown,I=e.handleKeyUp;return h.createElement(o.Popover,v.__assign({autoFocus:!1,enforceFocus:!1,isOpen:s.state.isOpen,disabled:a,position:o.Position.BOTTOM_LEFT},d,{className:m()(e.className,d.className),onInteraction:s.handlePopoverInteraction,popoverClassName:m()(r.SELECT_POPOVER,d.popoverClassName),onOpening:s.handlePopoverOpening,onOpened:s.handlePopoverOpened,onClosing:s.handlePopoverClosing}),h.createElement("div",{onKeyDown:s.state.isOpen?y:s.handleTargetKeyDown,onKeyUp:s.state.isOpen?I:void 0},s.props.children),h.createElement("div",{onKeyDown:y,onKeyUp:I},i?f:void 0,e.itemList))},s.handleTargetKeyDown=function(e){e.which!==o.Keys.ARROW_UP&&e.which!==o.Keys.ARROW_DOWN||(e.preventDefault(),s.setState({isOpen:!0}))},s.handleItemSelect=function(e,t){s.setState({isOpen:!1}),o.Utils.safeInvoke(s.props.onItemSelect,e,t)},s.handlePopoverInteraction=function(e){s.setState({isOpen:e});var t=s.props.popoverProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.onInteraction,e)},s.handlePopoverOpening=function(e){var t=s.props,n=t.popoverProps,r=void 0===n?{}:n,i=t.resetOnClose;s.previousFocusedElement=document.activeElement,i&&s.resetQuery(),o.Utils.safeInvoke(r.onOpening,e)},s.handlePopoverOpened=function(e){null!=s.list&&s.list.scrollActiveItemIntoView(),requestAnimationFrame(function(){var e=s.props.inputProps;!1!==(void 0===e?{}:e).autoFocus&&null!=s.input&&s.input.focus()});var t=s.props.popoverProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.onOpened,e)},s.handlePopoverClosing=function(e){requestAnimationFrame(function(){void 0!==s.previousFocusedElement&&(s.previousFocusedElement.focus(),s.previousFocusedElement=void 0)});var t=s.props.popoverProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.onClosing,e)},s.resetQuery=function(){return s.list&&s.list.setQuery("",!0)},s.state={isOpen:!1},s}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.filterable,e.inputProps,e.popoverProps,v.__rest(e,["filterable","inputProps","popoverProps"]));return h.createElement(this.TypedQueryList,v.__assign({},t,{onItemSelect:this.handleItemSelect,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.list&&this.list.scrollActiveItemIntoView()},t.prototype.maybeRenderClearButton=function(e){return e.length>0?h.createElement(o.Button,{icon:"cross",minimal:!0,onClick:this.resetQuery}):void 0},t.displayName=o.DISPLAYNAME_PREFIX+".Select",t}(h.PureComponent),S=function(e){function t(t,n){var s=e.call(this,t,n)||this;return s.TypedQueryList=y.ofType(),s.refHandlers={input:function(e){s.input=e;var t=s.props.inputProps,n=void 0===t?{}:t;o.Utils.safeInvoke(n.inputRef,e)},queryList:function(e){return s.queryList=e}},s.renderQueryList=function(e){var t=s.props,n=t.inputProps,i=void 0===n?{}:n,p=t.popoverProps,a=void 0===p?{}:p,l=s.state,u=l.isOpen,c=l.selectedItem,d=e.handleKeyDown,f=e.handleKeyUp,y=i.placeholder,I=void 0===y?"Search...":y,P=c?s.props.inputValueRenderer(c):"";return h.createElement(o.Popover,v.__assign({autoFocus:!1,enforceFocus:!1,isOpen:u,position:o.Position.BOTTOM_LEFT},a,{className:m()(e.className,a.className),onInteraction:s.handlePopoverInteraction,popoverClassName:m()(r.SELECT_POPOVER,a.popoverClassName),onOpened:s.handlePopoverOpened}),h.createElement(o.InputGroup,v.__assign({},i,{placeholder:u&&P?P:I,inputRef:s.refHandlers.input,onChange:e.handleQueryChange,onFocus:s.handleInputFocus,onKeyDown:s.getTargetKeyDownHandler(d),onKeyUp:s.getTargetKeyUpHandler(f),value:u?e.query:P})),h.createElement("div",{onKeyDown:d,onKeyUp:f},e.itemList))},s.selectText=function(){requestAnimationFrame(function(){null!=s.input&&s.input.setSelectionRange(0,s.input.value.length)})},s.handleInputFocus=function(e){var t=s.props,n=t.openOnKeyDown,r=t.inputProps,i=void 0===r?{}:r;s.selectText(),n||s.setState({isOpen:!0}),o.Utils.safeInvoke(i.onFocus,e)},s.handleItemSelect=function(e,t){var n;s.props.closeOnSelect?(null!=s.input&&s.input.blur(),n=!1):(null!=s.input&&s.input.focus(),s.selectText(),n=!0),void 0===s.props.selectedItem?s.setState({isOpen:n,selectedItem:e}):s.setState({isOpen:n}),o.Utils.safeInvoke(s.props.onItemSelect,e,t)},s.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var t=s.props.popoverProps,n=void 0===t?{}:t;null!=s.input&&s.input!==document.activeElement&&s.setState({isOpen:!1}),o.Utils.safeInvoke(n.onInteraction,e)})},s.handlePopoverOpened=function(e){var t=s.props.popoverProps,n=void 0===t?{}:t;null!=s.queryList&&s.queryList.scrollActiveItemIntoView(),o.Utils.safeInvoke(n.onOpened,e)},s.getTargetKeyDownHandler=function(e){return function(t){var n=t.which,r=s.props,i=r.inputProps,p=void 0===i?{}:i,a=r.openOnKeyDown;n===o.Keys.ESCAPE||n===o.Keys.TAB?(null!=s.input&&s.input.blur(),s.setState({isOpen:!1})):a&&n!==o.Keys.BACKSPACE&&n!==o.Keys.ARROW_LEFT&&n!==o.Keys.ARROW_RIGHT&&s.setState({isOpen:!0}),s.state.isOpen&&o.Utils.safeInvoke(e,t),o.Utils.safeInvoke(p.onKeyDown,t)}},s.getTargetKeyUpHandler=function(e){return function(t){var n=s.props.inputProps,r=void 0===n?{}:n;s.state.isOpen&&o.Utils.safeInvoke(e,t),o.Utils.safeInvoke(r.onKeyUp,t)}},s.state={isOpen:t.popoverProps&&t.popoverProps.isOpen||!1,selectedItem:s.getInitialSelectedItem()},s}return v.__extends(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.inputProps,e.popoverProps,v.__rest(e,["inputProps","popoverProps"]));return h.createElement(this.TypedQueryList,v.__assign({},t,{onItemSelect:this.handleItemSelect,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentWillReceiveProps=function(e){void 0!==e.selectedItem&&e.selectedItem!==this.state.selectedItem&&this.setState({selectedItem:e.selectedItem})},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.queryList&&this.queryList.scrollActiveItemIntoView()},t.prototype.getInitialSelectedItem=function(){return void 0!==this.props.selectedItem?this.props.selectedItem:void 0!==this.props.defaultSelectedItem?this.props.defaultSelectedItem:null},t.displayName=o.DISPLAYNAME_PREFIX+".Suggest",t.defaultProps={closeOnSelect:!0,openOnKeyDown:!1},t}(h.PureComponent);n.d(t,"Classes",function(){return r}),n.d(t,"renderFilteredItems",function(){return d}),n.d(t,"Omnibar",function(){return E}),n.d(t,"QueryList",function(){return y}),n.d(t,"getFirstEnabledItem",function(){return g}),n.d(t,"MultiSelect",function(){return C}),n.d(t,"Select",function(){return _}),n.d(t,"Suggest",function(){return S})}])}); |
@@ -96,2 +96,11 @@ /// <reference types="react" /> | ||
/** | ||
* When `activeItem` is controlled, whether the active item should _always_ | ||
* be scrolled into view when the prop changes. If `false`, only changes | ||
* that result from built-in interactions (clicking, querying, or using | ||
* arrow keys) will scroll the active item into view. Ignored if the | ||
* `activeItem` prop is omitted (uncontrolled behavior). | ||
* @default true | ||
*/ | ||
scrollToActiveItem?: boolean; | ||
/** | ||
* Query string passed to `itemListPredicate` or `itemPredicate` to filter items. | ||
@@ -98,0 +107,0 @@ * This value is controlled: its state must be managed externally by attaching an `onChange` |
@@ -25,3 +25,3 @@ "use strict"; | ||
var handleKeyDown = listProps.handleKeyDown, handleKeyUp = listProps.handleKeyUp; | ||
var handlers = isOpen && listProps.query.length > 0 ? { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp } : {}; | ||
var handlers = isOpen ? { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp } : {}; | ||
return (React.createElement(core_1.Overlay, tslib_1.__assign({ hasBackdrop: true }, overlayProps, { isOpen: isOpen, className: classnames_1.default(common_1.Classes.OMNIBAR_OVERLAY, overlayProps.className), onClose: _this.handleOverlayClose }), | ||
@@ -28,0 +28,0 @@ React.createElement("div", tslib_1.__assign({ className: classnames_1.default(common_1.Classes.OMNIBAR, listProps.className) }, handlers), |
@@ -74,2 +74,8 @@ /// <reference types="react" /> | ||
private shouldCheckActiveItemInViewport; | ||
/** | ||
* The item that we expect to be the next selected active item (based on click | ||
* or key interactions). When scrollToActiveItem = false, used to detect if | ||
* an unexpected external change to the active item has been made. | ||
*/ | ||
private expectedNextActiveItem; | ||
constructor(props: IQueryListProps<T>, context?: any); | ||
@@ -76,0 +82,0 @@ render(): JSX.Element; |
@@ -25,2 +25,8 @@ "use strict"; | ||
_this.shouldCheckActiveItemInViewport = false; | ||
/** | ||
* The item that we expect to be the next selected active item (based on click | ||
* or key interactions). When scrollToActiveItem = false, used to detect if | ||
* an unexpected external change to the active item has been made. | ||
*/ | ||
_this.expectedNextActiveItem = null; | ||
/** default `itemListRenderer` implementation */ | ||
@@ -120,2 +126,8 @@ _this.renderItemList = function (listProps) { | ||
QueryList.prototype.scrollActiveItemIntoView = function () { | ||
var scrollToActiveItem = this.props.scrollToActiveItem !== false; | ||
var externalChangeToActiveItem = this.expectedNextActiveItem !== this.props.activeItem; | ||
this.expectedNextActiveItem = null; | ||
if (!scrollToActiveItem && externalChangeToActiveItem) { | ||
return; | ||
} | ||
var activeElement = this.getActiveElement(); | ||
@@ -188,2 +200,3 @@ if (this.itemsParentRef != null && activeElement != null) { | ||
QueryList.prototype.setActiveItem = function (activeItem) { | ||
this.expectedNextActiveItem = activeItem; | ||
if (this.props.activeItem === undefined) { | ||
@@ -190,0 +203,0 @@ // indicate that the active item may need to be scrolled into view after update. |
@@ -96,2 +96,11 @@ /// <reference types="react" /> | ||
/** | ||
* When `activeItem` is controlled, whether the active item should _always_ | ||
* be scrolled into view when the prop changes. If `false`, only changes | ||
* that result from built-in interactions (clicking, querying, or using | ||
* arrow keys) will scroll the active item into view. Ignored if the | ||
* `activeItem` prop is omitted (uncontrolled behavior). | ||
* @default true | ||
*/ | ||
scrollToActiveItem?: boolean; | ||
/** | ||
* Query string passed to `itemListPredicate` or `itemPredicate` to filter items. | ||
@@ -98,0 +107,0 @@ * This value is controlled: its state must be managed externally by attaching an `onChange` |
@@ -23,3 +23,3 @@ /* | ||
var handleKeyDown = listProps.handleKeyDown, handleKeyUp = listProps.handleKeyUp; | ||
var handlers = isOpen && listProps.query.length > 0 ? { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp } : {}; | ||
var handlers = isOpen ? { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp } : {}; | ||
return (React.createElement(Overlay, tslib_1.__assign({ hasBackdrop: true }, overlayProps, { isOpen: isOpen, className: classNames(Classes.OMNIBAR_OVERLAY, overlayProps.className), onClose: _this.handleOverlayClose }), | ||
@@ -26,0 +26,0 @@ React.createElement("div", tslib_1.__assign({ className: classNames(Classes.OMNIBAR, listProps.className) }, handlers), |
@@ -74,2 +74,8 @@ /// <reference types="react" /> | ||
private shouldCheckActiveItemInViewport; | ||
/** | ||
* The item that we expect to be the next selected active item (based on click | ||
* or key interactions). When scrollToActiveItem = false, used to detect if | ||
* an unexpected external change to the active item has been made. | ||
*/ | ||
private expectedNextActiveItem; | ||
constructor(props: IQueryListProps<T>, context?: any); | ||
@@ -76,0 +82,0 @@ render(): JSX.Element; |
@@ -23,2 +23,8 @@ /* | ||
_this.shouldCheckActiveItemInViewport = false; | ||
/** | ||
* The item that we expect to be the next selected active item (based on click | ||
* or key interactions). When scrollToActiveItem = false, used to detect if | ||
* an unexpected external change to the active item has been made. | ||
*/ | ||
_this.expectedNextActiveItem = null; | ||
/** default `itemListRenderer` implementation */ | ||
@@ -118,2 +124,8 @@ _this.renderItemList = function (listProps) { | ||
QueryList.prototype.scrollActiveItemIntoView = function () { | ||
var scrollToActiveItem = this.props.scrollToActiveItem !== false; | ||
var externalChangeToActiveItem = this.expectedNextActiveItem !== this.props.activeItem; | ||
this.expectedNextActiveItem = null; | ||
if (!scrollToActiveItem && externalChangeToActiveItem) { | ||
return; | ||
} | ||
var activeElement = this.getActiveElement(); | ||
@@ -186,2 +198,3 @@ if (this.itemsParentRef != null && activeElement != null) { | ||
QueryList.prototype.setActiveItem = function (activeItem) { | ||
this.expectedNextActiveItem = activeItem; | ||
if (this.props.activeItem === undefined) { | ||
@@ -188,0 +201,0 @@ // indicate that the active item may need to be scrolled into view after update. |
{ | ||
"name": "@blueprintjs/select", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Components related to selecting items from a list", | ||
@@ -36,3 +36,3 @@ "main": "lib/cjs/index.js", | ||
"dependencies": { | ||
"@blueprintjs/core": "^3.6.0", | ||
"@blueprintjs/core": "^3.9.0", | ||
"classnames": "^2.2", | ||
@@ -42,4 +42,4 @@ "tslib": "^1.9.0" | ||
"devDependencies": { | ||
"@blueprintjs/karma-build-scripts": "^0.8.0", | ||
"@blueprintjs/node-build-scripts": "^0.7.0", | ||
"@blueprintjs/karma-build-scripts": "*", | ||
"@blueprintjs/node-build-scripts": "*", | ||
"enzyme": "^3.3.0", | ||
@@ -46,0 +46,0 @@ "karma": "^1.7.1", |
@@ -116,2 +116,12 @@ /* | ||
/** | ||
* When `activeItem` is controlled, whether the active item should _always_ | ||
* be scrolled into view when the prop changes. If `false`, only changes | ||
* that result from built-in interactions (clicking, querying, or using | ||
* arrow keys) will scroll the active item into view. Ignored if the | ||
* `activeItem` prop is omitted (uncontrolled behavior). | ||
* @default true | ||
*/ | ||
scrollToActiveItem?: boolean; | ||
/** | ||
* Query string passed to `itemListPredicate` or `itemPredicate` to filter items. | ||
@@ -118,0 +128,0 @@ * This value is controlled: its state must be managed externally by attaching an `onChange` |
@@ -63,15 +63,23 @@ @# Select | ||
The `InputGroup` value is managed by `Select`'s internal state and is not exposed via props. If you would like to control it, you can circumvent `Select` state by passing your `value` state and `onChange` handler to `inputProps`. You can then query the `items` array directly and omit both predicate props. | ||
The input value can be controlled with the `query` and `onQueryChange` props. _Do not use `inputProps` for this;_ the component ignores `inputProps.value` and `inputProps.onChange` in favor of `query` and `onQueryChange` (as noted in the prop documentation). | ||
The focused item (for keyboard interactions) can be controlled with the `activeItem` and `onActiveItemChange` props. | ||
```tsx | ||
// controlling query involves controlling the input and doing your own filtering | ||
<FilmSelect | ||
inputProps={{ value: this.state.myQuery, onChange: this.handleChange }} | ||
items={myFilter(ALL_ITEMS, this.state.myQuery)} | ||
itemRenderer={...} | ||
onItemSelect={...} | ||
// controlled active item | ||
activeItem={this.state.myActiveItem} | ||
onActiveItemChange={this.handleActiveItemChange} | ||
// controlled query | ||
query={this.state.myQuery} | ||
onQueryChange={this.handleQueryChange} | ||
/> | ||
``` | ||
This "escape hatch" can be used to implement all sorts of advanced behavior on top of the basic `Select` interactions, such as windowed filtering for large data sets. | ||
This controlled usage allows you to implement all sorts of advanced behavior on | ||
top of the basic `Select` interactions, such as windowed filtering for large | ||
data sets. | ||
@@ -78,0 +86,0 @@ @## JavaScript API |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
291896
4089
226
5
6
0
21
Updated@blueprintjs/core@^3.9.0