Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VSelect.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.defaultMenuProps = undefined;
  6. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  7. require('../../../src/stylus/components/_text-fields.styl');
  8. require('../../../src/stylus/components/_select.styl');
  9. var _VChip = require('../VChip');
  10. var _VChip2 = _interopRequireDefault(_VChip);
  11. var _VMenu = require('../VMenu');
  12. var _VMenu2 = _interopRequireDefault(_VMenu);
  13. var _VSelectList = require('./VSelectList');
  14. var _VSelectList2 = _interopRequireDefault(_VSelectList);
  15. var _VTextField = require('../VTextField/VTextField');
  16. var _VTextField2 = _interopRequireDefault(_VTextField);
  17. var _comparable = require('../../mixins/comparable');
  18. var _comparable2 = _interopRequireDefault(_comparable);
  19. var _filterable = require('../../mixins/filterable');
  20. var _filterable2 = _interopRequireDefault(_filterable);
  21. var _clickOutside = require('../../directives/click-outside');
  22. var _clickOutside2 = _interopRequireDefault(_clickOutside);
  23. var _helpers = require('../../util/helpers');
  24. var _console = require('../../util/console');
  25. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } // Styles
  27. // Components
  28. // Extensions
  29. // Mixins
  30. // Directives
  31. // Helpers
  32. var defaultMenuProps = exports.defaultMenuProps = {
  33. closeOnClick: false,
  34. closeOnContentClick: false,
  35. openOnClick: false,
  36. maxHeight: 300
  37. };
  38. /* @vue/component */
  39. exports.default = _VTextField2.default.extend({
  40. name: 'v-select',
  41. directives: {
  42. ClickOutside: _clickOutside2.default
  43. },
  44. mixins: [_comparable2.default, _filterable2.default],
  45. props: {
  46. appendIcon: {
  47. type: String,
  48. default: '$vuetify.icons.dropdown'
  49. },
  50. appendIconCb: Function,
  51. attach: {
  52. type: null,
  53. default: false
  54. },
  55. browserAutocomplete: {
  56. type: String,
  57. default: 'on'
  58. },
  59. cacheItems: Boolean,
  60. chips: Boolean,
  61. clearable: Boolean,
  62. deletableChips: Boolean,
  63. dense: Boolean,
  64. hideSelected: Boolean,
  65. items: {
  66. type: Array,
  67. default: function _default() {
  68. return [];
  69. }
  70. },
  71. itemAvatar: {
  72. type: [String, Array, Function],
  73. default: 'avatar'
  74. },
  75. itemDisabled: {
  76. type: [String, Array, Function],
  77. default: 'disabled'
  78. },
  79. itemText: {
  80. type: [String, Array, Function],
  81. default: 'text'
  82. },
  83. itemValue: {
  84. type: [String, Array, Function],
  85. default: 'value'
  86. },
  87. menuProps: {
  88. type: [String, Array, Object],
  89. default: function _default() {
  90. return defaultMenuProps;
  91. }
  92. },
  93. multiple: Boolean,
  94. openOnClear: Boolean,
  95. returnObject: Boolean,
  96. searchInput: {
  97. default: null
  98. },
  99. smallChips: Boolean
  100. },
  101. data: function data(vm) {
  102. return {
  103. attrsInput: { role: 'combobox' },
  104. cachedItems: vm.cacheItems ? vm.items : [],
  105. content: null,
  106. isBooted: false,
  107. isMenuActive: false,
  108. lastItem: 20,
  109. // As long as a value is defined, show it
  110. // Otherwise, check if multiple
  111. // to determine which default to provide
  112. lazyValue: vm.value !== undefined ? vm.value : vm.multiple ? [] : undefined,
  113. selectedIndex: -1,
  114. selectedItems: [],
  115. keyboardLookupPrefix: '',
  116. keyboardLookupLastTime: 0
  117. };
  118. },
  119. computed: {
  120. /* All items that the select has */
  121. allItems: function allItems() {
  122. return this.filterDuplicates(this.cachedItems.concat(this.items));
  123. },
  124. classes: function classes() {
  125. return Object.assign({}, _VTextField2.default.options.computed.classes.call(this), {
  126. 'v-select': true,
  127. 'v-select--chips': this.hasChips,
  128. 'v-select--chips--small': this.smallChips,
  129. 'v-select--is-menu-active': this.isMenuActive
  130. });
  131. },
  132. /* Used by other components to overwrite */
  133. computedItems: function computedItems() {
  134. return this.allItems;
  135. },
  136. counterValue: function counterValue() {
  137. return this.multiple ? this.selectedItems.length : (this.getText(this.selectedItems[0]) || '').toString().length;
  138. },
  139. directives: function directives() {
  140. return this.isFocused ? [{
  141. name: 'click-outside',
  142. value: this.blur,
  143. args: {
  144. closeConditional: this.closeConditional
  145. }
  146. }] : undefined;
  147. },
  148. dynamicHeight: function dynamicHeight() {
  149. return 'auto';
  150. },
  151. hasChips: function hasChips() {
  152. return this.chips || this.smallChips;
  153. },
  154. hasSlot: function hasSlot() {
  155. return Boolean(this.hasChips || this.$scopedSlots.selection);
  156. },
  157. isDirty: function isDirty() {
  158. return this.selectedItems.length > 0;
  159. },
  160. listData: function listData() {
  161. var scopeId = this.$vnode && this.$vnode.context.$options._scopeId;
  162. return {
  163. attrs: scopeId ? _defineProperty({}, scopeId, true) : null,
  164. props: {
  165. action: this.multiple && !this.isHidingSelected,
  166. color: this.color,
  167. dense: this.dense,
  168. hideSelected: this.hideSelected,
  169. items: this.virtualizedItems,
  170. noDataText: this.$vuetify.t(this.noDataText),
  171. selectedItems: this.selectedItems,
  172. itemAvatar: this.itemAvatar,
  173. itemDisabled: this.itemDisabled,
  174. itemValue: this.itemValue,
  175. itemText: this.itemText
  176. },
  177. on: {
  178. select: this.selectItem
  179. },
  180. scopedSlots: {
  181. item: this.$scopedSlots.item
  182. }
  183. };
  184. },
  185. staticList: function staticList() {
  186. if (this.$slots['no-data'] || this.$slots['prepend-item'] || this.$slots['append-item']) {
  187. (0, _console.consoleError)('assert: staticList should not be called if slots are used');
  188. }
  189. return this.$createElement(_VSelectList2.default, this.listData);
  190. },
  191. virtualizedItems: function virtualizedItems() {
  192. return this.$_menuProps.auto ? this.computedItems : this.computedItems.slice(0, this.lastItem);
  193. },
  194. menuCanShow: function menuCanShow() {
  195. return true;
  196. },
  197. $_menuProps: function $_menuProps() {
  198. var normalisedProps = void 0;
  199. normalisedProps = typeof this.menuProps === 'string' ? this.menuProps.split(',') : this.menuProps;
  200. if (Array.isArray(normalisedProps)) {
  201. normalisedProps = normalisedProps.reduce(function (acc, p) {
  202. acc[p.trim()] = true;
  203. return acc;
  204. }, {});
  205. }
  206. return _extends({}, defaultMenuProps, {
  207. value: this.menuCanShow && this.isMenuActive,
  208. nudgeBottom: this.nudgeBottom ? this.nudgeBottom : normalisedProps.offsetY ? 1 : 0
  209. }, normalisedProps);
  210. }
  211. },
  212. watch: {
  213. internalValue: function internalValue(val) {
  214. this.initialValue = val;
  215. this.setSelectedItems();
  216. },
  217. isBooted: function isBooted() {
  218. var _this = this;
  219. this.$nextTick(function () {
  220. if (_this.content && _this.content.addEventListener) {
  221. _this.content.addEventListener('scroll', _this.onScroll, false);
  222. }
  223. });
  224. },
  225. isMenuActive: function isMenuActive(val) {
  226. if (!val) return;
  227. this.isBooted = true;
  228. },
  229. items: {
  230. immediate: true,
  231. handler: function handler(val) {
  232. if (this.cacheItems) {
  233. this.cachedItems = this.filterDuplicates(this.cachedItems.concat(val));
  234. }
  235. this.setSelectedItems();
  236. }
  237. }
  238. },
  239. mounted: function mounted() {
  240. this.content = this.$refs.menu && this.$refs.menu.$refs.content;
  241. },
  242. methods: {
  243. /** @public */
  244. blur: function blur(e) {
  245. this.isMenuActive = false;
  246. this.isFocused = false;
  247. this.$refs.input && this.$refs.input.blur();
  248. this.selectedIndex = -1;
  249. this.onBlur(e);
  250. },
  251. /** @public */
  252. activateMenu: function activateMenu() {
  253. this.isMenuActive = true;
  254. },
  255. clearableCallback: function clearableCallback() {
  256. var _this2 = this;
  257. this.setValue(this.multiple ? [] : undefined);
  258. this.$nextTick(function () {
  259. return _this2.$refs.input.focus();
  260. });
  261. if (this.openOnClear) this.isMenuActive = true;
  262. },
  263. closeConditional: function closeConditional(e) {
  264. return (
  265. // Click originates from outside the menu content
  266. !!this.content && !this.content.contains(e.target) &&
  267. // Click originates from outside the element
  268. !!this.$el && !this.$el.contains(e.target) && e.target !== this.$el
  269. );
  270. },
  271. filterDuplicates: function filterDuplicates(arr) {
  272. var uniqueValues = new Map();
  273. for (var index = 0; index < arr.length; ++index) {
  274. var item = arr[index];
  275. var val = this.getValue(item);
  276. // TODO: comparator
  277. !uniqueValues.has(val) && uniqueValues.set(val, item);
  278. }
  279. return Array.from(uniqueValues.values());
  280. },
  281. findExistingIndex: function findExistingIndex(item) {
  282. var _this3 = this;
  283. var itemValue = this.getValue(item);
  284. return (this.internalValue || []).findIndex(function (i) {
  285. return _this3.valueComparator(_this3.getValue(i), itemValue);
  286. });
  287. },
  288. genChipSelection: function genChipSelection(item, index) {
  289. var _this4 = this;
  290. var isDisabled = this.disabled || this.readonly || this.getDisabled(item);
  291. return this.$createElement(_VChip2.default, {
  292. staticClass: 'v-chip--select-multi',
  293. attrs: { tabindex: -1 },
  294. props: {
  295. close: this.deletableChips && !isDisabled,
  296. disabled: isDisabled,
  297. selected: index === this.selectedIndex,
  298. small: this.smallChips
  299. },
  300. on: {
  301. click: function click(e) {
  302. if (isDisabled) return;
  303. e.stopPropagation();
  304. _this4.selectedIndex = index;
  305. },
  306. input: function input() {
  307. return _this4.onChipInput(item);
  308. }
  309. },
  310. key: this.getValue(item)
  311. }, this.getText(item));
  312. },
  313. genCommaSelection: function genCommaSelection(item, index, last) {
  314. // Item may be an object
  315. // TODO: Remove JSON.stringify
  316. var key = JSON.stringify(this.getValue(item));
  317. var color = index === this.selectedIndex && this.color;
  318. var isDisabled = this.disabled || this.getDisabled(item);
  319. return this.$createElement('div', this.setTextColor(color, {
  320. staticClass: 'v-select__selection v-select__selection--comma',
  321. 'class': {
  322. 'v-select__selection--disabled': isDisabled
  323. },
  324. key: key
  325. }), '' + this.getText(item) + (last ? '' : ', '));
  326. },
  327. genDefaultSlot: function genDefaultSlot() {
  328. var selections = this.genSelections();
  329. var input = this.genInput();
  330. // If the return is an empty array
  331. // push the input
  332. if (Array.isArray(selections)) {
  333. selections.push(input);
  334. // Otherwise push it into children
  335. } else {
  336. selections.children = selections.children || [];
  337. selections.children.push(input);
  338. }
  339. return [this.$createElement('div', {
  340. staticClass: 'v-select__slot',
  341. directives: this.directives
  342. }, [this.genLabel(), this.prefix ? this.genAffix('prefix') : null, selections, this.suffix ? this.genAffix('suffix') : null, this.genClearIcon(), this.genIconSlot()]), this.genMenu(), this.genProgress()];
  343. },
  344. genInput: function genInput() {
  345. var input = _VTextField2.default.options.methods.genInput.call(this);
  346. input.data.domProps.value = null;
  347. input.data.attrs.readonly = true;
  348. input.data.attrs['aria-readonly'] = String(this.readonly);
  349. input.data.on.keypress = this.onKeyPress;
  350. return input;
  351. },
  352. genList: function genList() {
  353. // If there's no slots, we can use a cached VNode to improve performance
  354. if (this.$slots['no-data'] || this.$slots['prepend-item'] || this.$slots['append-item']) {
  355. return this.genListWithSlot();
  356. } else {
  357. return this.staticList;
  358. }
  359. },
  360. genListWithSlot: function genListWithSlot() {
  361. var _this5 = this;
  362. var slots = ['prepend-item', 'no-data', 'append-item'].filter(function (slotName) {
  363. return _this5.$slots[slotName];
  364. }).map(function (slotName) {
  365. return _this5.$createElement('template', {
  366. slot: slotName
  367. }, _this5.$slots[slotName]);
  368. });
  369. // Requires destructuring due to Vue
  370. // modifying the `on` property when passed
  371. // as a referenced object
  372. return this.$createElement(_VSelectList2.default, _extends({}, this.listData), slots);
  373. },
  374. genMenu: function genMenu() {
  375. var _this6 = this;
  376. var props = this.$_menuProps;
  377. props.activator = this.$refs['input-slot'];
  378. // Deprecate using menu props directly
  379. // TODO: remove (2.0)
  380. var inheritedProps = Object.keys(_VMenu2.default.options.props);
  381. var deprecatedProps = Object.keys(this.$attrs).reduce(function (acc, attr) {
  382. if (inheritedProps.includes((0, _helpers.camelize)(attr))) acc.push(attr);
  383. return acc;
  384. }, []);
  385. var _iteratorNormalCompletion = true;
  386. var _didIteratorError = false;
  387. var _iteratorError = undefined;
  388. try {
  389. for (var _iterator = deprecatedProps[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  390. var prop = _step.value;
  391. props[(0, _helpers.camelize)(prop)] = this.$attrs[prop];
  392. }
  393. } catch (err) {
  394. _didIteratorError = true;
  395. _iteratorError = err;
  396. } finally {
  397. try {
  398. if (!_iteratorNormalCompletion && _iterator.return) {
  399. _iterator.return();
  400. }
  401. } finally {
  402. if (_didIteratorError) {
  403. throw _iteratorError;
  404. }
  405. }
  406. }
  407. if (process.env.NODE_ENV !== 'production') {
  408. if (deprecatedProps.length) {
  409. var multiple = deprecatedProps.length > 1;
  410. var replacement = deprecatedProps.reduce(function (acc, p) {
  411. acc[(0, _helpers.camelize)(p)] = _this6.$attrs[p];
  412. return acc;
  413. }, {});
  414. var _props = deprecatedProps.map(function (p) {
  415. return '\'' + p + '\'';
  416. }).join(', ');
  417. var separator = multiple ? '\n' : '\'';
  418. var onlyBools = Object.keys(replacement).every(function (prop) {
  419. var propType = _VMenu2.default.options.props[prop];
  420. var value = replacement[prop];
  421. return value === true || (propType.type || propType) === Boolean && value === '';
  422. });
  423. if (onlyBools) {
  424. replacement = Object.keys(replacement).join(', ');
  425. } else {
  426. replacement = JSON.stringify(replacement, null, multiple ? 2 : 0).replace(/"([^(")"]+)":/g, '$1:').replace(/"/g, '\'');
  427. }
  428. (0, _console.consoleWarn)(_props + ' ' + (multiple ? 'are' : 'is') + ' deprecated, use ' + ('' + separator + (onlyBools ? '' : ':') + 'menu-props="' + replacement + '"' + separator + ' instead'), this);
  429. }
  430. }
  431. // Attach to root el so that
  432. // menu covers prepend/append icons
  433. if (
  434. // TODO: make this a computed property or helper or something
  435. this.attach === '' || // If used as a boolean prop (<v-menu attach>)
  436. this.attach === true || // If bound to a boolean (<v-menu :attach="true">)
  437. this.attach === 'attach' // If bound as boolean prop in pug (v-menu(attach))
  438. ) {
  439. props.attach = this.$el;
  440. } else {
  441. props.attach = this.attach;
  442. }
  443. return this.$createElement(_VMenu2.default, {
  444. props: props,
  445. on: {
  446. input: function input(val) {
  447. _this6.isMenuActive = val;
  448. _this6.isFocused = val;
  449. }
  450. },
  451. ref: 'menu'
  452. }, [this.genList()]);
  453. },
  454. genSelections: function genSelections() {
  455. var length = this.selectedItems.length;
  456. var children = new Array(length);
  457. var genSelection = void 0;
  458. if (this.$scopedSlots.selection) {
  459. genSelection = this.genSlotSelection;
  460. } else if (this.hasChips) {
  461. genSelection = this.genChipSelection;
  462. } else {
  463. genSelection = this.genCommaSelection;
  464. }
  465. while (length--) {
  466. children[length] = genSelection(this.selectedItems[length], length, length === children.length - 1);
  467. }
  468. return this.$createElement('div', {
  469. staticClass: 'v-select__selections'
  470. }, children);
  471. },
  472. genSlotSelection: function genSlotSelection(item, index) {
  473. return this.$scopedSlots.selection({
  474. parent: this,
  475. item: item,
  476. index: index,
  477. selected: index === this.selectedIndex,
  478. disabled: this.disabled || this.readonly
  479. });
  480. },
  481. getMenuIndex: function getMenuIndex() {
  482. return this.$refs.menu ? this.$refs.menu.listIndex : -1;
  483. },
  484. getDisabled: function getDisabled(item) {
  485. return (0, _helpers.getPropertyFromItem)(item, this.itemDisabled, false);
  486. },
  487. getText: function getText(item) {
  488. return (0, _helpers.getPropertyFromItem)(item, this.itemText, item);
  489. },
  490. getValue: function getValue(item) {
  491. return (0, _helpers.getPropertyFromItem)(item, this.itemValue, this.getText(item));
  492. },
  493. onBlur: function onBlur(e) {
  494. this.$emit('blur', e);
  495. },
  496. onChipInput: function onChipInput(item) {
  497. if (this.multiple) this.selectItem(item);else this.setValue(null);
  498. // If all items have been deleted,
  499. // open `v-menu`
  500. if (this.selectedItems.length === 0) {
  501. this.isMenuActive = true;
  502. } else {
  503. this.isMenuActive = false;
  504. }
  505. this.selectedIndex = -1;
  506. },
  507. onClick: function onClick() {
  508. if (this.isDisabled) return;
  509. this.isMenuActive = true;
  510. if (!this.isFocused) {
  511. this.isFocused = true;
  512. this.$emit('focus');
  513. }
  514. },
  515. onEnterDown: function onEnterDown() {
  516. this.onBlur();
  517. },
  518. onEscDown: function onEscDown(e) {
  519. e.preventDefault();
  520. if (this.isMenuActive) {
  521. e.stopPropagation();
  522. this.isMenuActive = false;
  523. }
  524. },
  525. onKeyPress: function onKeyPress(e) {
  526. var _this7 = this;
  527. if (this.multiple) return;
  528. var KEYBOARD_LOOKUP_THRESHOLD = 1000; // milliseconds
  529. var now = performance.now();
  530. if (now - this.keyboardLookupLastTime > KEYBOARD_LOOKUP_THRESHOLD) {
  531. this.keyboardLookupPrefix = '';
  532. }
  533. this.keyboardLookupPrefix += e.key.toLowerCase();
  534. this.keyboardLookupLastTime = now;
  535. var index = this.allItems.findIndex(function (item) {
  536. return _this7.getText(item).toLowerCase().startsWith(_this7.keyboardLookupPrefix);
  537. });
  538. var item = this.allItems[index];
  539. if (index !== -1) {
  540. this.setValue(this.returnObject ? item : this.getValue(item));
  541. setTimeout(function () {
  542. return _this7.setMenuIndex(index);
  543. });
  544. }
  545. },
  546. onKeyDown: function onKeyDown(e) {
  547. var keyCode = e.keyCode;
  548. // If enter, space, up, or down is pressed, open menu
  549. if (!this.readonly && !this.isMenuActive && [_helpers.keyCodes.enter, _helpers.keyCodes.space, _helpers.keyCodes.up, _helpers.keyCodes.down].includes(keyCode)) this.activateMenu();
  550. if (this.isMenuActive && this.$refs.menu) this.$refs.menu.changeListIndex(e);
  551. // This should do something different
  552. if (keyCode === _helpers.keyCodes.enter) return this.onEnterDown(e);
  553. // If escape deactivate the menu
  554. if (keyCode === _helpers.keyCodes.esc) return this.onEscDown(e);
  555. // If tab - select item or close menu
  556. if (keyCode === _helpers.keyCodes.tab) return this.onTabDown(e);
  557. },
  558. onMouseUp: function onMouseUp(e) {
  559. var _this8 = this;
  560. if (this.hasMouseDown) {
  561. var appendInner = this.$refs['append-inner'];
  562. // If append inner is present
  563. // and the target is itself
  564. // or inside, toggle menu
  565. if (this.isMenuActive && appendInner && (appendInner === e.target || appendInner.contains(e.target))) {
  566. this.$nextTick(function () {
  567. return _this8.isMenuActive = !_this8.isMenuActive;
  568. });
  569. // If user is clicking in the container
  570. // and field is enclosed, activate it
  571. } else if (this.isEnclosed && !this.isDisabled) {
  572. this.isMenuActive = true;
  573. }
  574. }
  575. _VTextField2.default.options.methods.onMouseUp.call(this, e);
  576. },
  577. onScroll: function onScroll() {
  578. var _this9 = this;
  579. if (!this.isMenuActive) {
  580. requestAnimationFrame(function () {
  581. return _this9.content.scrollTop = 0;
  582. });
  583. } else {
  584. if (this.lastItem >= this.computedItems.length) return;
  585. var showMoreItems = this.content.scrollHeight - (this.content.scrollTop + this.content.clientHeight) < 200;
  586. if (showMoreItems) {
  587. this.lastItem += 20;
  588. }
  589. }
  590. },
  591. onTabDown: function onTabDown(e) {
  592. var menuIndex = this.getMenuIndex();
  593. var listTile = this.$refs.menu.tiles[menuIndex];
  594. // An item that is selected by
  595. // menu-index should toggled
  596. if (listTile && listTile.className.indexOf('v-list__tile--highlighted') > -1 && this.isMenuActive && menuIndex > -1) {
  597. e.preventDefault();
  598. e.stopPropagation();
  599. listTile.click();
  600. } else {
  601. // If we make it here,
  602. // the user has no selected indexes
  603. // and is probably tabbing out
  604. this.blur(e);
  605. }
  606. },
  607. selectItem: function selectItem(item) {
  608. var _this10 = this;
  609. if (!this.multiple) {
  610. this.setValue(this.returnObject ? item : this.getValue(item));
  611. this.isMenuActive = false;
  612. } else {
  613. var internalValue = (this.internalValue || []).slice();
  614. var i = this.findExistingIndex(item);
  615. i !== -1 ? internalValue.splice(i, 1) : internalValue.push(item);
  616. this.setValue(internalValue.map(function (i) {
  617. return _this10.returnObject ? i : _this10.getValue(i);
  618. }));
  619. // When selecting multiple
  620. // adjust menu after each
  621. // selection
  622. this.$nextTick(function () {
  623. _this10.$refs.menu && _this10.$refs.menu.updateDimensions();
  624. });
  625. }
  626. },
  627. setMenuIndex: function setMenuIndex(index) {
  628. this.$refs.menu && (this.$refs.menu.listIndex = index);
  629. },
  630. setSelectedItems: function setSelectedItems() {
  631. var _this11 = this;
  632. var selectedItems = [];
  633. var values = !this.multiple || !Array.isArray(this.internalValue) ? [this.internalValue] : this.internalValue;
  634. var _loop = function _loop(value) {
  635. var index = _this11.allItems.findIndex(function (v) {
  636. return _this11.valueComparator(_this11.getValue(v), _this11.getValue(value));
  637. });
  638. if (index > -1) {
  639. selectedItems.push(_this11.allItems[index]);
  640. }
  641. };
  642. var _iteratorNormalCompletion2 = true;
  643. var _didIteratorError2 = false;
  644. var _iteratorError2 = undefined;
  645. try {
  646. for (var _iterator2 = values[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  647. var value = _step2.value;
  648. _loop(value);
  649. }
  650. } catch (err) {
  651. _didIteratorError2 = true;
  652. _iteratorError2 = err;
  653. } finally {
  654. try {
  655. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  656. _iterator2.return();
  657. }
  658. } finally {
  659. if (_didIteratorError2) {
  660. throw _iteratorError2;
  661. }
  662. }
  663. }
  664. this.selectedItems = selectedItems;
  665. },
  666. setValue: function setValue(value) {
  667. var oldValue = this.internalValue;
  668. this.internalValue = value;
  669. value !== oldValue && this.$emit('change', value);
  670. }
  671. }
  672. });
  673. //# sourceMappingURL=VSelect.js.map