component.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @license
  3. * Copyright 2017 Google Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. import { __extends } from "tslib";
  24. import { MDCComponent } from '@material/base/component';
  25. import { MDCFormFieldFoundation } from './foundation';
  26. /** MDC Form Field */
  27. var MDCFormField = /** @class */ (function (_super) {
  28. __extends(MDCFormField, _super);
  29. function MDCFormField() {
  30. return _super !== null && _super.apply(this, arguments) || this;
  31. }
  32. MDCFormField.attachTo = function (root) {
  33. return new MDCFormField(root);
  34. };
  35. MDCFormField.prototype.labelEl = function () {
  36. var LABEL_SELECTOR = MDCFormFieldFoundation.strings.LABEL_SELECTOR;
  37. return this.root.querySelector(LABEL_SELECTOR);
  38. };
  39. MDCFormField.prototype.getDefaultFoundation = function () {
  40. var _this = this;
  41. // DO NOT INLINE this variable. For backward compatibility, foundations take
  42. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  43. // methods, we need a separate, strongly typed adapter variable.
  44. var adapter = {
  45. activateInputRipple: function () {
  46. if (_this.input && _this.input.ripple) {
  47. _this.input.ripple.activate();
  48. }
  49. },
  50. deactivateInputRipple: function () {
  51. if (_this.input && _this.input.ripple) {
  52. _this.input.ripple.deactivate();
  53. }
  54. },
  55. deregisterInteractionHandler: function (evtType, handler) {
  56. var _a;
  57. (_a = _this.labelEl()) === null || _a === void 0 ? void 0 : _a.removeEventListener(evtType, handler);
  58. },
  59. registerInteractionHandler: function (evtType, handler) {
  60. var _a;
  61. (_a = _this.labelEl()) === null || _a === void 0 ? void 0 : _a.addEventListener(evtType, handler);
  62. },
  63. };
  64. return new MDCFormFieldFoundation(adapter);
  65. };
  66. return MDCFormField;
  67. }(MDCComponent));
  68. export { MDCFormField };
  69. //# sourceMappingURL=component.js.map