index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Component, triggerEvent } from '../_util/simply';
  2. import { InputDefaultProps } from './props';
  3. import mixinValue from '../mixins/value';
  4. Component(InputDefaultProps, {
  5. onChange: function (e) {
  6. var value = e.detail.value;
  7. if (!this.isControlled()) {
  8. this.update(value);
  9. }
  10. triggerEvent(this, 'change', value, e);
  11. },
  12. onFocus: function (e) {
  13. var value = e.detail.value;
  14. this.setData({
  15. selfFocus: true,
  16. });
  17. triggerEvent(this, 'focus', value, e);
  18. },
  19. onBlur: function (e) {
  20. var value = e.detail.value;
  21. this.setData({
  22. selfFocus: false,
  23. });
  24. triggerEvent(this, 'blur', value, e);
  25. },
  26. onConfirm: function (e) {
  27. var value = e.detail.value;
  28. triggerEvent(this, 'confirm', value, e);
  29. },
  30. onClear: function (e) {
  31. if (!this.isControlled()) {
  32. this.update('');
  33. }
  34. triggerEvent(this, 'change', '', e);
  35. },
  36. }, {
  37. selfFocus: false,
  38. }, [mixinValue({ scopeKey: 'state' })]);