123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { Directive, ElementRef, EventEmitter, Input, Output } from '@angular/core';
  2. import { isPresent, isTrueProperty } from '../../util/util';
  3. /**
  4. * @name Option
  5. * @description
  6. * `ion-option` is a child component of `ion-select`. Similar to the native option element, `ion-option` can take a value and a selected property.
  7. *
  8. * @demo /docs/demos/src/select/
  9. */
  10. export class Option {
  11. constructor(_elementRef) {
  12. this._elementRef = _elementRef;
  13. this._selected = false;
  14. this._disabled = false;
  15. /**
  16. * @output {any} Event to evaluate when option is selected.
  17. */
  18. this.ionSelect = new EventEmitter();
  19. }
  20. /**
  21. * @input {boolean} If true, the user cannot interact with this element.
  22. */
  23. get disabled() {
  24. return this._disabled;
  25. }
  26. set disabled(val) {
  27. this._disabled = isTrueProperty(val);
  28. }
  29. /**
  30. * @input {boolean} If true, the element is selected.
  31. */
  32. get selected() {
  33. return this._selected;
  34. }
  35. set selected(val) {
  36. this._selected = isTrueProperty(val);
  37. }
  38. /**
  39. * @input {any} The value of the option.
  40. */
  41. get value() {
  42. if (isPresent(this._value)) {
  43. return this._value;
  44. }
  45. return this.text;
  46. }
  47. set value(val) {
  48. this._value = val;
  49. }
  50. /**
  51. * @hidden
  52. */
  53. get text() {
  54. return this._elementRef.nativeElement.textContent;
  55. }
  56. }
  57. Option.decorators = [
  58. { type: Directive, args: [{
  59. selector: 'ion-option'
  60. },] },
  61. ];
  62. /** @nocollapse */
  63. Option.ctorParameters = () => [
  64. { type: ElementRef, },
  65. ];
  66. Option.propDecorators = {
  67. 'disabled': [{ type: Input },],
  68. 'selected': [{ type: Input },],
  69. 'value': [{ type: Input },],
  70. 'ionSelect': [{ type: Output },],
  71. };
  72. //# sourceMappingURL=option.js.map