index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Component, triggerEvent } from '../../_util/simply';
  2. import { InputBlurDefaultProps } from './props';
  3. import mixinValue from '../../mixins/value';
  4. Component(InputBlurDefaultProps, {
  5. onChange: function (e) {
  6. var value = e.detail.value;
  7. if (this.isControlled()) {
  8. this.update(value, {}, true);
  9. }
  10. triggerEvent(this, 'change', value, e);
  11. },
  12. onFocus: function (e) {
  13. var value = e.detail.value;
  14. this.focus = true;
  15. triggerEvent(this, 'focus', value, e);
  16. },
  17. onBlur: function (e) {
  18. var value = e.detail.value;
  19. this.focus = false;
  20. if (this.isControlled()) {
  21. this.update(this.props.value);
  22. }
  23. triggerEvent(this, 'blur', value, e);
  24. },
  25. onConfirm: function (e) {
  26. var value = e.detail.value;
  27. triggerEvent(this, 'confirm', value, e);
  28. },
  29. }, undefined, [
  30. mixinValue({
  31. scopeKey: 'state',
  32. transformValue: function (value, extra, updateWithoutFocusCheck) {
  33. if (!updateWithoutFocusCheck && this.focus) {
  34. return {
  35. needUpdate: false,
  36. };
  37. }
  38. return {
  39. needUpdate: true,
  40. value: value,
  41. };
  42. },
  43. }),
  44. ], {
  45. focus: false,
  46. });