ion-input.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { proxyCustomElement, HTMLElement, createEvent, forceUpdate, Build, h, Host } from '@stencil/core/internal/client';
  5. import { c as createNotchController } from './notch-controller.js';
  6. import { l as debounceEvent, i as inheritAriaAttributes, d as inheritAttributes, c as componentOnReady } from './helpers.js';
  7. import { c as createSlotMutationController, g as getCounterText } from './input.utils.js';
  8. import { h as hostContext, c as createColorClasses } from './theme.js';
  9. import { j as closeCircle, k as closeSharp } from './index7.js';
  10. import { b as getIonMode } from './ionic-global.js';
  11. import { d as defineCustomElement$2 } from './icon.js';
  12. const inputIosCss = ".sc-ion-input-ios-h{--placeholder-color:initial;--placeholder-font-style:initial;--placeholder-font-weight:initial;--placeholder-opacity:var(--ion-placeholder-opacity, 0.6);--padding-top:0px;--padding-end:0px;--padding-bottom:0px;--padding-start:0px;--background:transparent;--color:initial;--border-style:solid;--highlight-color-focused:var(--ion-color-primary, #0054e9);--highlight-color-valid:var(--ion-color-success, #2dd55b);--highlight-color-invalid:var(--ion-color-danger, #c5000f);--highlight-color:var(--highlight-color-focused);display:block;position:relative;width:100%;min-height:44px;padding:0 !important;color:var(--color);font-family:var(--ion-font-family, inherit);z-index:2}ion-item[slot=start].sc-ion-input-ios-h,ion-item [slot=start].sc-ion-input-ios-h,ion-item[slot=end].sc-ion-input-ios-h,ion-item [slot=end].sc-ion-input-ios-h{width:auto}.ion-color.sc-ion-input-ios-h{--highlight-color-focused:var(--ion-color-base)}.input-label-placement-floating.sc-ion-input-ios-h,.input-label-placement-stacked.sc-ion-input-ios-h{min-height:56px}.native-input.sc-ion-input-ios{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;display:inline-block;position:relative;-ms-flex:1;flex:1;width:100%;max-width:100%;height:100%;max-height:100%;border:0;outline:none;background:transparent;-webkit-box-sizing:border-box;box-sizing:border-box;-webkit-appearance:none;-moz-appearance:none;appearance:none;z-index:1}.native-input.sc-ion-input-ios::-webkit-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios::-moz-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios:-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios::-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios::placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios:-webkit-autofill{background-color:transparent}.native-input.sc-ion-input-ios:invalid{-webkit-box-shadow:none;box-shadow:none}.native-input.sc-ion-input-ios::-ms-clear{display:none}.cloned-input.sc-ion-input-ios{top:0;bottom:0;position:absolute;pointer-events:none}.cloned-input.sc-ion-input-ios{inset-inline-start:0}.cloned-input.sc-ion-input-ios:disabled{opacity:1}.input-clear-icon.sc-ion-input-ios{-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto;margin-top:auto;margin-bottom:auto;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;background-position:center;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:30px;height:30px;border:0;outline:none;background-color:transparent;background-repeat:no-repeat;color:var(--ion-color-step-600, var(--ion-text-color-step-400, #666666));visibility:hidden;-webkit-appearance:none;-moz-appearance:none;appearance:none}.in-item-color.sc-ion-input-ios-h .input-clear-icon.sc-ion-input-ios{color:inherit}.input-clear-icon.sc-ion-input-ios:focus{opacity:0.5}.has-value.sc-ion-input-ios-h .input-clear-icon.sc-ion-input-ios{visibility:visible}.input-wrapper.sc-ion-input-ios{-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);border-radius:var(--border-radius);display:-ms-flexbox;display:flex;position:relative;-ms-flex-positive:1;flex-grow:1;-ms-flex-align:stretch;align-items:stretch;height:inherit;min-height:inherit;-webkit-transition:background-color 15ms linear;transition:background-color 15ms linear;background:var(--background);line-height:normal}.native-wrapper.sc-ion-input-ios{display:-ms-flexbox;display:flex;position:relative;-ms-flex-positive:1;flex-grow:1;-ms-flex-align:center;align-items:center;width:100%}.ion-touched.ion-invalid.sc-ion-input-ios-h{--highlight-color:var(--highlight-color-invalid)}.ion-valid.sc-ion-input-ios-h{--highlight-color:var(--highlight-color-valid)}.input-bottom.sc-ion-input-ios{-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end);padding-top:5px;padding-bottom:0;display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;border-top:var(--border-width) var(--border-style) var(--border-color);font-size:0.75rem;white-space:normal}.has-focus.ion-valid.sc-ion-input-ios-h,.ion-touched.ion-invalid.sc-ion-input-ios-h{--border-color:var(--highlight-color)}.input-bottom.sc-ion-input-ios .error-text.sc-ion-input-ios{display:none;color:var(--highlight-color-invalid)}.input-bottom.sc-ion-input-ios .helper-text.sc-ion-input-ios{display:block;color:var(--ion-color-step-700, var(--ion-text-color-step-300, #4d4d4d))}.ion-touched.ion-invalid.sc-ion-input-ios-h .input-bottom.sc-ion-input-ios .error-text.sc-ion-input-ios{display:block}.ion-touched.ion-invalid.sc-ion-input-ios-h .input-bottom.sc-ion-input-ios .helper-text.sc-ion-input-ios{display:none}.input-bottom.sc-ion-input-ios .counter.sc-ion-input-ios{-webkit-margin-start:auto;margin-inline-start:auto;color:var(--ion-color-step-700, var(--ion-text-color-step-300, #4d4d4d));white-space:nowrap;-webkit-padding-start:16px;padding-inline-start:16px}.has-focus.sc-ion-input-ios-h input.sc-ion-input-ios{caret-color:var(--highlight-color)}.label-text-wrapper.sc-ion-input-ios{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;max-width:200px;-webkit-transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), transform 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), transform 150ms cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 150ms cubic-bezier(0.4, 0, 0.2, 1);pointer-events:none}.label-text.sc-ion-input-ios,.sc-ion-input-ios-s>[slot=label]{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.label-text-wrapper-hidden.sc-ion-input-ios,.input-outline-notch-hidden.sc-ion-input-ios{display:none}.input-wrapper.sc-ion-input-ios input.sc-ion-input-ios{-webkit-transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1)}.input-label-placement-start.sc-ion-input-ios-h .input-wrapper.sc-ion-input-ios{-ms-flex-direction:row;flex-direction:row}.input-label-placement-start.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}.input-label-placement-end.sc-ion-input-ios-h .input-wrapper.sc-ion-input-ios{-ms-flex-direction:row-reverse;flex-direction:row-reverse}.input-label-placement-end.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios{-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0;margin-top:0;margin-bottom:0}.input-label-placement-fixed.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}.input-label-placement-fixed.sc-ion-input-ios-h .label-text.sc-ion-input-ios{-ms-flex:0 0 100px;flex:0 0 100px;width:100px;min-width:100px;max-width:200px}.input-label-placement-stacked.sc-ion-input-ios-h .input-wrapper.sc-ion-input-ios,.input-label-placement-floating.sc-ion-input-ios-h .input-wrapper.sc-ion-input-ios{-ms-flex-direction:column;flex-direction:column;-ms-flex-align:start;align-items:start}.input-label-placement-stacked.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,.input-label-placement-floating.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios{-webkit-transform-origin:left top;transform-origin:left top;max-width:100%;z-index:2}[dir=rtl].sc-ion-input-ios-h -no-combinator.input-label-placement-stacked.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,[dir=rtl] .sc-ion-input-ios-h -no-combinator.input-label-placement-stacked.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,[dir=rtl].input-label-placement-stacked.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,[dir=rtl] .input-label-placement-stacked.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,[dir=rtl].sc-ion-input-ios-h -no-combinator.input-label-placement-floating.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,[dir=rtl] .sc-ion-input-ios-h -no-combinator.input-label-placement-floating.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,[dir=rtl].input-label-placement-floating.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios,[dir=rtl] .input-label-placement-floating.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios{-webkit-transform-origin:right top;transform-origin:right top}@supports selector(:dir(rtl)){.input-label-placement-stacked.sc-ion-input-ios-h:dir(rtl) .label-text-wrapper.sc-ion-input-ios,.input-label-placement-floating.sc-ion-input-ios-h:dir(rtl) .label-text-wrapper.sc-ion-input-ios{-webkit-transform-origin:right top;transform-origin:right top}}.input-label-placement-stacked.sc-ion-input-ios-h input.sc-ion-input-ios,.input-label-placement-floating.sc-ion-input-ios-h input.sc-ion-input-ios{margin-left:0;margin-right:0;margin-top:1px;margin-bottom:0}.input-label-placement-floating.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios{-webkit-transform:translateY(100%) scale(1);transform:translateY(100%) scale(1)}.input-label-placement-floating.sc-ion-input-ios-h input.sc-ion-input-ios{opacity:0}.has-focus.input-label-placement-floating.sc-ion-input-ios-h input.sc-ion-input-ios,.has-value.input-label-placement-floating.sc-ion-input-ios-h input.sc-ion-input-ios{opacity:1}.label-floating.sc-ion-input-ios-h .label-text-wrapper.sc-ion-input-ios{-webkit-transform:translateY(50%) scale(0.75);transform:translateY(50%) scale(0.75);max-width:calc(100% / 0.75)}.sc-ion-input-ios-s>[slot=start]:last-of-type{-webkit-margin-end:16px;margin-inline-end:16px;-webkit-margin-start:0;margin-inline-start:0}.sc-ion-input-ios-s>[slot=end]:first-of-type{-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0}.sc-ion-input-ios-h[disabled].sc-ion-input-ios-s>ion-input-password-toggle,.sc-ion-input-ios-h[disabled] .sc-ion-input-ios-s>ion-input-password-toggle,.sc-ion-input-ios-h[readonly].sc-ion-input-ios-s>ion-input-password-toggle,.sc-ion-input-ios-h[readonly] .sc-ion-input-ios-s>ion-input-password-toggle{display:none}.sc-ion-input-ios-h{--border-width:0.55px;--border-color:var(--ion-item-border-color, var(--ion-border-color, var(--ion-color-step-250, var(--ion-background-color-step-250, #c8c7cc))));--highlight-height:0px;font-size:inherit}.input-clear-icon.sc-ion-input-ios ion-icon.sc-ion-input-ios{width:18px;height:18px}.input-disabled.sc-ion-input-ios-h{opacity:0.3}.sc-ion-input-ios-s>ion-button[slot=start].button-has-icon-only,.sc-ion-input-ios-s>ion-button[slot=end].button-has-icon-only{--border-radius:50%;--padding-start:0;--padding-end:0;--padding-top:0;--padding-bottom:0;aspect-ratio:1}";
  13. const IonInputIosStyle0 = inputIosCss;
  14. const inputMdCss = ".sc-ion-input-md-h{--placeholder-color:initial;--placeholder-font-style:initial;--placeholder-font-weight:initial;--placeholder-opacity:var(--ion-placeholder-opacity, 0.6);--padding-top:0px;--padding-end:0px;--padding-bottom:0px;--padding-start:0px;--background:transparent;--color:initial;--border-style:solid;--highlight-color-focused:var(--ion-color-primary, #0054e9);--highlight-color-valid:var(--ion-color-success, #2dd55b);--highlight-color-invalid:var(--ion-color-danger, #c5000f);--highlight-color:var(--highlight-color-focused);display:block;position:relative;width:100%;min-height:44px;padding:0 !important;color:var(--color);font-family:var(--ion-font-family, inherit);z-index:2}ion-item[slot=start].sc-ion-input-md-h,ion-item [slot=start].sc-ion-input-md-h,ion-item[slot=end].sc-ion-input-md-h,ion-item [slot=end].sc-ion-input-md-h{width:auto}.ion-color.sc-ion-input-md-h{--highlight-color-focused:var(--ion-color-base)}.input-label-placement-floating.sc-ion-input-md-h,.input-label-placement-stacked.sc-ion-input-md-h{min-height:56px}.native-input.sc-ion-input-md{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;display:inline-block;position:relative;-ms-flex:1;flex:1;width:100%;max-width:100%;height:100%;max-height:100%;border:0;outline:none;background:transparent;-webkit-box-sizing:border-box;box-sizing:border-box;-webkit-appearance:none;-moz-appearance:none;appearance:none;z-index:1}.native-input.sc-ion-input-md::-webkit-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md::-moz-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md:-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md::-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md::placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md:-webkit-autofill{background-color:transparent}.native-input.sc-ion-input-md:invalid{-webkit-box-shadow:none;box-shadow:none}.native-input.sc-ion-input-md::-ms-clear{display:none}.cloned-input.sc-ion-input-md{top:0;bottom:0;position:absolute;pointer-events:none}.cloned-input.sc-ion-input-md{inset-inline-start:0}.cloned-input.sc-ion-input-md:disabled{opacity:1}.input-clear-icon.sc-ion-input-md{-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto;margin-top:auto;margin-bottom:auto;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;background-position:center;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:30px;height:30px;border:0;outline:none;background-color:transparent;background-repeat:no-repeat;color:var(--ion-color-step-600, var(--ion-text-color-step-400, #666666));visibility:hidden;-webkit-appearance:none;-moz-appearance:none;appearance:none}.in-item-color.sc-ion-input-md-h .input-clear-icon.sc-ion-input-md{color:inherit}.input-clear-icon.sc-ion-input-md:focus{opacity:0.5}.has-value.sc-ion-input-md-h .input-clear-icon.sc-ion-input-md{visibility:visible}.input-wrapper.sc-ion-input-md{-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);border-radius:var(--border-radius);display:-ms-flexbox;display:flex;position:relative;-ms-flex-positive:1;flex-grow:1;-ms-flex-align:stretch;align-items:stretch;height:inherit;min-height:inherit;-webkit-transition:background-color 15ms linear;transition:background-color 15ms linear;background:var(--background);line-height:normal}.native-wrapper.sc-ion-input-md{display:-ms-flexbox;display:flex;position:relative;-ms-flex-positive:1;flex-grow:1;-ms-flex-align:center;align-items:center;width:100%}.ion-touched.ion-invalid.sc-ion-input-md-h{--highlight-color:var(--highlight-color-invalid)}.ion-valid.sc-ion-input-md-h{--highlight-color:var(--highlight-color-valid)}.input-bottom.sc-ion-input-md{-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end);padding-top:5px;padding-bottom:0;display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;border-top:var(--border-width) var(--border-style) var(--border-color);font-size:0.75rem;white-space:normal}.has-focus.ion-valid.sc-ion-input-md-h,.ion-touched.ion-invalid.sc-ion-input-md-h{--border-color:var(--highlight-color)}.input-bottom.sc-ion-input-md .error-text.sc-ion-input-md{display:none;color:var(--highlight-color-invalid)}.input-bottom.sc-ion-input-md .helper-text.sc-ion-input-md{display:block;color:var(--ion-color-step-700, var(--ion-text-color-step-300, #4d4d4d))}.ion-touched.ion-invalid.sc-ion-input-md-h .input-bottom.sc-ion-input-md .error-text.sc-ion-input-md{display:block}.ion-touched.ion-invalid.sc-ion-input-md-h .input-bottom.sc-ion-input-md .helper-text.sc-ion-input-md{display:none}.input-bottom.sc-ion-input-md .counter.sc-ion-input-md{-webkit-margin-start:auto;margin-inline-start:auto;color:var(--ion-color-step-700, var(--ion-text-color-step-300, #4d4d4d));white-space:nowrap;-webkit-padding-start:16px;padding-inline-start:16px}.has-focus.sc-ion-input-md-h input.sc-ion-input-md{caret-color:var(--highlight-color)}.label-text-wrapper.sc-ion-input-md{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;max-width:200px;-webkit-transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), transform 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:color 150ms cubic-bezier(0.4, 0, 0.2, 1), transform 150ms cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 150ms cubic-bezier(0.4, 0, 0.2, 1);pointer-events:none}.label-text.sc-ion-input-md,.sc-ion-input-md-s>[slot=label]{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.label-text-wrapper-hidden.sc-ion-input-md,.input-outline-notch-hidden.sc-ion-input-md{display:none}.input-wrapper.sc-ion-input-md input.sc-ion-input-md{-webkit-transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1)}.input-label-placement-start.sc-ion-input-md-h .input-wrapper.sc-ion-input-md{-ms-flex-direction:row;flex-direction:row}.input-label-placement-start.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}.input-label-placement-end.sc-ion-input-md-h .input-wrapper.sc-ion-input-md{-ms-flex-direction:row-reverse;flex-direction:row-reverse}.input-label-placement-end.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0;margin-top:0;margin-bottom:0}.input-label-placement-fixed.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}.input-label-placement-fixed.sc-ion-input-md-h .label-text.sc-ion-input-md{-ms-flex:0 0 100px;flex:0 0 100px;width:100px;min-width:100px;max-width:200px}.input-label-placement-stacked.sc-ion-input-md-h .input-wrapper.sc-ion-input-md,.input-label-placement-floating.sc-ion-input-md-h .input-wrapper.sc-ion-input-md{-ms-flex-direction:column;flex-direction:column;-ms-flex-align:start;align-items:start}.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-transform-origin:left top;transform-origin:left top;max-width:100%;z-index:2}[dir=rtl].sc-ion-input-md-h -no-combinator.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .sc-ion-input-md-h -no-combinator.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl].input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl].sc-ion-input-md-h -no-combinator.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .sc-ion-input-md-h -no-combinator.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl].input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-transform-origin:right top;transform-origin:right top}@supports selector(:dir(rtl)){.input-label-placement-stacked.sc-ion-input-md-h:dir(rtl) .label-text-wrapper.sc-ion-input-md,.input-label-placement-floating.sc-ion-input-md-h:dir(rtl) .label-text-wrapper.sc-ion-input-md{-webkit-transform-origin:right top;transform-origin:right top}}.input-label-placement-stacked.sc-ion-input-md-h input.sc-ion-input-md,.input-label-placement-floating.sc-ion-input-md-h input.sc-ion-input-md{margin-left:0;margin-right:0;margin-top:1px;margin-bottom:0}.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-transform:translateY(100%) scale(1);transform:translateY(100%) scale(1)}.input-label-placement-floating.sc-ion-input-md-h input.sc-ion-input-md{opacity:0}.has-focus.input-label-placement-floating.sc-ion-input-md-h input.sc-ion-input-md,.has-value.input-label-placement-floating.sc-ion-input-md-h input.sc-ion-input-md{opacity:1}.label-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-transform:translateY(50%) scale(0.75);transform:translateY(50%) scale(0.75);max-width:calc(100% / 0.75)}.sc-ion-input-md-s>[slot=start]:last-of-type{-webkit-margin-end:16px;margin-inline-end:16px;-webkit-margin-start:0;margin-inline-start:0}.sc-ion-input-md-s>[slot=end]:first-of-type{-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0}.sc-ion-input-md-h[disabled].sc-ion-input-md-s>ion-input-password-toggle,.sc-ion-input-md-h[disabled] .sc-ion-input-md-s>ion-input-password-toggle,.sc-ion-input-md-h[readonly].sc-ion-input-md-s>ion-input-password-toggle,.sc-ion-input-md-h[readonly] .sc-ion-input-md-s>ion-input-password-toggle{display:none}.input-fill-solid.sc-ion-input-md-h{--background:var(--ion-color-step-50, var(--ion-background-color-step-50, #f2f2f2));--border-color:var(--ion-color-step-500, var(--ion-background-color-step-500, gray));--border-radius:4px;--padding-start:16px;--padding-end:16px;min-height:56px}.input-fill-solid.sc-ion-input-md-h .input-wrapper.sc-ion-input-md{border-bottom:var(--border-width) var(--border-style) var(--border-color)}.has-focus.input-fill-solid.ion-valid.sc-ion-input-md-h,.input-fill-solid.ion-touched.ion-invalid.sc-ion-input-md-h{--border-color:var(--highlight-color)}.input-fill-solid.sc-ion-input-md-h .input-bottom.sc-ion-input-md{border-top:none}@media (any-hover: hover){.input-fill-solid.sc-ion-input-md-h:hover{--background:var(--ion-color-step-100, var(--ion-background-color-step-100, #e6e6e6));--border-color:var(--ion-color-step-750, var(--ion-background-color-step-750, #404040))}}.input-fill-solid.has-focus.sc-ion-input-md-h{--background:var(--ion-color-step-150, var(--ion-background-color-step-150, #d9d9d9));--border-color:var(--ion-color-step-750, var(--ion-background-color-step-750, #404040))}.input-fill-solid.sc-ion-input-md-h .input-wrapper.sc-ion-input-md{border-start-start-radius:var(--border-radius);border-start-end-radius:var(--border-radius);border-end-end-radius:0px;border-end-start-radius:0px}.label-floating.input-fill-solid.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{max-width:calc(100% / 0.75)}.input-fill-outline.sc-ion-input-md-h{--border-color:var(--ion-color-step-300, var(--ion-background-color-step-300, #b3b3b3));--border-radius:4px;--padding-start:16px;--padding-end:16px;min-height:56px}.input-fill-outline.input-shape-round.sc-ion-input-md-h{--border-radius:28px;--padding-start:32px;--padding-end:32px}.has-focus.input-fill-outline.ion-valid.sc-ion-input-md-h,.input-fill-outline.ion-touched.ion-invalid.sc-ion-input-md-h{--border-color:var(--highlight-color)}@media (any-hover: hover){.input-fill-outline.sc-ion-input-md-h:hover{--border-color:var(--ion-color-step-750, var(--ion-background-color-step-750, #404040))}}.input-fill-outline.has-focus.sc-ion-input-md-h{--border-width:var(--highlight-height);--border-color:var(--highlight-color)}.input-fill-outline.sc-ion-input-md-h .input-bottom.sc-ion-input-md{border-top:none}.input-fill-outline.sc-ion-input-md-h .input-wrapper.sc-ion-input-md{border-bottom:none}.input-fill-outline.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,.input-fill-outline.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-transform-origin:left top;transform-origin:left top;position:absolute;max-width:calc(100% - var(--padding-start) - var(--padding-end))}[dir=rtl].sc-ion-input-md-h -no-combinator.input-fill-outline.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .sc-ion-input-md-h -no-combinator.input-fill-outline.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl].input-fill-outline.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .input-fill-outline.input-label-placement-stacked.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl].sc-ion-input-md-h -no-combinator.input-fill-outline.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .sc-ion-input-md-h -no-combinator.input-fill-outline.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl].input-fill-outline.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,[dir=rtl] .input-fill-outline.input-label-placement-floating.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-transform-origin:right top;transform-origin:right top}@supports selector(:dir(rtl)){.input-fill-outline.input-label-placement-stacked.sc-ion-input-md-h:dir(rtl) .label-text-wrapper.sc-ion-input-md,.input-fill-outline.input-label-placement-floating.sc-ion-input-md-h:dir(rtl) .label-text-wrapper.sc-ion-input-md{-webkit-transform-origin:right top;transform-origin:right top}}.input-fill-outline.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{position:relative}.label-floating.input-fill-outline.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{-webkit-transform:translateY(-32%) scale(0.75);transform:translateY(-32%) scale(0.75);margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;max-width:calc((100% - var(--padding-start) - var(--padding-end) - 8px) / 0.75)}.input-fill-outline.input-label-placement-stacked.sc-ion-input-md-h input.sc-ion-input-md,.input-fill-outline.input-label-placement-floating.sc-ion-input-md-h input.sc-ion-input-md{margin-left:0;margin-right:0;margin-top:6px;margin-bottom:6px}.input-fill-outline.sc-ion-input-md-h .input-outline-container.sc-ion-input-md{left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:absolute;width:100%;height:100%}.input-fill-outline.sc-ion-input-md-h .input-outline-start.sc-ion-input-md,.input-fill-outline.sc-ion-input-md-h .input-outline-end.sc-ion-input-md{pointer-events:none}.input-fill-outline.sc-ion-input-md-h .input-outline-start.sc-ion-input-md,.input-fill-outline.sc-ion-input-md-h .input-outline-notch.sc-ion-input-md,.input-fill-outline.sc-ion-input-md-h .input-outline-end.sc-ion-input-md{border-top:var(--border-width) var(--border-style) var(--border-color);border-bottom:var(--border-width) var(--border-style) var(--border-color)}.input-fill-outline.sc-ion-input-md-h .input-outline-notch.sc-ion-input-md{max-width:calc(100% - var(--padding-start) - var(--padding-end))}.input-fill-outline.sc-ion-input-md-h .notch-spacer.sc-ion-input-md{-webkit-padding-end:8px;padding-inline-end:8px;font-size:calc(1em * 0.75);opacity:0;pointer-events:none;-webkit-box-sizing:content-box;box-sizing:content-box}.input-fill-outline.sc-ion-input-md-h .input-outline-start.sc-ion-input-md{border-start-start-radius:var(--border-radius);border-start-end-radius:0px;border-end-end-radius:0px;border-end-start-radius:var(--border-radius);-webkit-border-start:var(--border-width) var(--border-style) var(--border-color);border-inline-start:var(--border-width) var(--border-style) var(--border-color);width:calc(var(--padding-start) - 4px)}.input-fill-outline.sc-ion-input-md-h .input-outline-end.sc-ion-input-md{-webkit-border-end:var(--border-width) var(--border-style) var(--border-color);border-inline-end:var(--border-width) var(--border-style) var(--border-color);border-start-start-radius:0px;border-start-end-radius:var(--border-radius);border-end-end-radius:var(--border-radius);border-end-start-radius:0px;-ms-flex-positive:1;flex-grow:1}.label-floating.input-fill-outline.sc-ion-input-md-h .input-outline-notch.sc-ion-input-md{border-top:none}.sc-ion-input-md-h{--border-width:1px;--border-color:var(--ion-item-border-color, var(--ion-border-color, var(--ion-color-step-150, var(--ion-background-color-step-150, rgba(0, 0, 0, 0.13)))));--highlight-height:2px;font-size:inherit}.input-clear-icon.sc-ion-input-md ion-icon.sc-ion-input-md{width:22px;height:22px}.input-disabled.sc-ion-input-md-h{opacity:0.38}.has-focus.ion-valid.sc-ion-input-md-h,.ion-touched.ion-invalid.sc-ion-input-md-h{--border-color:var(--highlight-color)}.input-bottom.sc-ion-input-md .counter.sc-ion-input-md{letter-spacing:0.0333333333em}.input-label-placement-floating.has-focus.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,.input-label-placement-stacked.has-focus.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{color:var(--highlight-color)}.has-focus.input-label-placement-floating.ion-valid.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,.input-label-placement-floating.ion-touched.ion-invalid.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,.has-focus.input-label-placement-stacked.ion-valid.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md,.input-label-placement-stacked.ion-touched.ion-invalid.sc-ion-input-md-h .label-text-wrapper.sc-ion-input-md{color:var(--highlight-color)}.input-highlight.sc-ion-input-md{bottom:-1px;position:absolute;width:100%;height:var(--highlight-height);-webkit-transform:scale(0);transform:scale(0);-webkit-transition:-webkit-transform 200ms;transition:-webkit-transform 200ms;transition:transform 200ms;transition:transform 200ms, -webkit-transform 200ms;background:var(--highlight-color)}.input-highlight.sc-ion-input-md{inset-inline-start:0}.has-focus.sc-ion-input-md-h .input-highlight.sc-ion-input-md{-webkit-transform:scale(1);transform:scale(1)}.in-item.sc-ion-input-md-h .input-highlight.sc-ion-input-md{bottom:0}.in-item.sc-ion-input-md-h .input-highlight.sc-ion-input-md{inset-inline-start:0}.input-shape-round.sc-ion-input-md-h{--border-radius:16px}.sc-ion-input-md-s>ion-button[slot=start].button-has-icon-only,.sc-ion-input-md-s>ion-button[slot=end].button-has-icon-only{--border-radius:50%;--padding-start:8px;--padding-end:8px;--padding-top:8px;--padding-bottom:8px;aspect-ratio:1;min-height:40px}";
  15. const IonInputMdStyle0 = inputMdCss;
  16. const Input = /*@__PURE__*/ proxyCustomElement(class Input extends HTMLElement {
  17. constructor() {
  18. super();
  19. this.__registerHost();
  20. this.ionInput = createEvent(this, "ionInput", 7);
  21. this.ionChange = createEvent(this, "ionChange", 7);
  22. this.ionBlur = createEvent(this, "ionBlur", 7);
  23. this.ionFocus = createEvent(this, "ionFocus", 7);
  24. this.inputId = `ion-input-${inputIds++}`;
  25. this.helperTextId = `${this.inputId}-helper-text`;
  26. this.errorTextId = `${this.inputId}-error-text`;
  27. this.inheritedAttributes = {};
  28. this.isComposing = false;
  29. /**
  30. * `true` if the input was cleared as a result of the user typing
  31. * with `clearOnEdit` enabled.
  32. *
  33. * Resets when the input loses focus.
  34. */
  35. this.didInputClearOnEdit = false;
  36. this.onInput = (ev) => {
  37. const input = ev.target;
  38. if (input) {
  39. this.value = input.value || '';
  40. }
  41. this.emitInputChange(ev);
  42. };
  43. this.onChange = (ev) => {
  44. this.emitValueChange(ev);
  45. };
  46. this.onBlur = (ev) => {
  47. this.hasFocus = false;
  48. if (this.focusedValue !== this.value) {
  49. /**
  50. * Emits the `ionChange` event when the input value
  51. * is different than the value when the input was focused.
  52. */
  53. this.emitValueChange(ev);
  54. }
  55. this.didInputClearOnEdit = false;
  56. this.ionBlur.emit(ev);
  57. };
  58. this.onFocus = (ev) => {
  59. this.hasFocus = true;
  60. this.focusedValue = this.value;
  61. this.ionFocus.emit(ev);
  62. };
  63. this.onKeydown = (ev) => {
  64. this.checkClearOnEdit(ev);
  65. };
  66. this.onCompositionStart = () => {
  67. this.isComposing = true;
  68. };
  69. this.onCompositionEnd = () => {
  70. this.isComposing = false;
  71. };
  72. this.clearTextInput = (ev) => {
  73. if (this.clearInput && !this.readonly && !this.disabled && ev) {
  74. ev.preventDefault();
  75. ev.stopPropagation();
  76. // Attempt to focus input again after pressing clear button
  77. this.setFocus();
  78. }
  79. this.value = '';
  80. this.emitInputChange(ev);
  81. };
  82. /**
  83. * Stops propagation when the label is clicked,
  84. * otherwise, two clicks will be triggered.
  85. */
  86. this.onLabelClick = (ev) => {
  87. // Only stop propagation if the click was directly on the label
  88. // and not on the input or other child elements
  89. if (ev.target === ev.currentTarget) {
  90. ev.stopPropagation();
  91. }
  92. };
  93. this.hasFocus = false;
  94. this.color = undefined;
  95. this.autocapitalize = 'off';
  96. this.autocomplete = 'off';
  97. this.autocorrect = 'off';
  98. this.autofocus = false;
  99. this.clearInput = false;
  100. this.clearInputIcon = undefined;
  101. this.clearOnEdit = undefined;
  102. this.counter = false;
  103. this.counterFormatter = undefined;
  104. this.debounce = undefined;
  105. this.disabled = false;
  106. this.enterkeyhint = undefined;
  107. this.errorText = undefined;
  108. this.fill = undefined;
  109. this.inputmode = undefined;
  110. this.helperText = undefined;
  111. this.label = undefined;
  112. this.labelPlacement = 'start';
  113. this.max = undefined;
  114. this.maxlength = undefined;
  115. this.min = undefined;
  116. this.minlength = undefined;
  117. this.multiple = undefined;
  118. this.name = this.inputId;
  119. this.pattern = undefined;
  120. this.placeholder = undefined;
  121. this.readonly = false;
  122. this.required = false;
  123. this.shape = undefined;
  124. this.spellcheck = false;
  125. this.step = undefined;
  126. this.type = 'text';
  127. this.value = '';
  128. }
  129. debounceChanged() {
  130. const { ionInput, debounce, originalIonInput } = this;
  131. /**
  132. * If debounce is undefined, we have to manually revert the ionInput emitter in case
  133. * debounce used to be set to a number. Otherwise, the event would stay debounced.
  134. */
  135. this.ionInput = debounce === undefined ? originalIonInput !== null && originalIonInput !== void 0 ? originalIonInput : ionInput : debounceEvent(ionInput, debounce);
  136. }
  137. /**
  138. * Whenever the type on the input changes we need
  139. * to update the internal type prop on the password
  140. * toggle so that that correct icon is shown.
  141. */
  142. onTypeChange() {
  143. const passwordToggle = this.el.querySelector('ion-input-password-toggle');
  144. if (passwordToggle) {
  145. passwordToggle.type = this.type;
  146. }
  147. }
  148. /**
  149. * Update the native input element when the value changes
  150. */
  151. valueChanged() {
  152. const nativeInput = this.nativeInput;
  153. const value = this.getValue();
  154. if (nativeInput && nativeInput.value !== value && !this.isComposing) {
  155. /**
  156. * Assigning the native input's value on attribute
  157. * value change, allows `ionInput` implementations
  158. * to override the control's value.
  159. *
  160. * Used for patterns such as input trimming (removing whitespace),
  161. * or input masking.
  162. */
  163. nativeInput.value = value;
  164. }
  165. }
  166. /**
  167. * dir is a globally enumerated attribute.
  168. * As a result, creating these as properties
  169. * can have unintended side effects. Instead, we
  170. * listen for attribute changes and inherit them
  171. * to the inner `<input>` element.
  172. */
  173. onDirChanged(newValue) {
  174. this.inheritedAttributes = Object.assign(Object.assign({}, this.inheritedAttributes), { dir: newValue });
  175. forceUpdate(this);
  176. }
  177. /**
  178. * This prevents the native input from emitting the click event.
  179. * Instead, the click event from the ion-input is emitted.
  180. */
  181. onClickCapture(ev) {
  182. const nativeInput = this.nativeInput;
  183. if (nativeInput && ev.target === nativeInput) {
  184. ev.stopPropagation();
  185. this.el.click();
  186. }
  187. }
  188. componentWillLoad() {
  189. this.inheritedAttributes = Object.assign(Object.assign({}, inheritAriaAttributes(this.el)), inheritAttributes(this.el, ['tabindex', 'title', 'data-form-type', 'dir']));
  190. }
  191. connectedCallback() {
  192. const { el } = this;
  193. this.slotMutationController = createSlotMutationController(el, ['label', 'start', 'end'], () => forceUpdate(this));
  194. this.notchController = createNotchController(el, () => this.notchSpacerEl, () => this.labelSlot);
  195. this.debounceChanged();
  196. if (Build.isBrowser) {
  197. document.dispatchEvent(new CustomEvent('ionInputDidLoad', {
  198. detail: this.el,
  199. }));
  200. }
  201. }
  202. componentDidLoad() {
  203. this.originalIonInput = this.ionInput;
  204. /**
  205. * Set the type on the password toggle in the event that this input's
  206. * type was set async and does not match the default type for the password toggle.
  207. * This can happen when the type is bound using a JS framework binding syntax
  208. * such as [type] in Angular.
  209. */
  210. this.onTypeChange();
  211. this.debounceChanged();
  212. }
  213. componentDidRender() {
  214. var _a;
  215. (_a = this.notchController) === null || _a === void 0 ? void 0 : _a.calculateNotchWidth();
  216. }
  217. disconnectedCallback() {
  218. if (Build.isBrowser) {
  219. document.dispatchEvent(new CustomEvent('ionInputDidUnload', {
  220. detail: this.el,
  221. }));
  222. }
  223. if (this.slotMutationController) {
  224. this.slotMutationController.destroy();
  225. this.slotMutationController = undefined;
  226. }
  227. if (this.notchController) {
  228. this.notchController.destroy();
  229. this.notchController = undefined;
  230. }
  231. }
  232. /**
  233. * Sets focus on the native `input` in `ion-input`. Use this method instead of the global
  234. * `input.focus()`.
  235. *
  236. * Developers who wish to focus an input when a page enters
  237. * should call `setFocus()` in the `ionViewDidEnter()` lifecycle method.
  238. *
  239. * Developers who wish to focus an input when an overlay is presented
  240. * should call `setFocus` after `didPresent` has resolved.
  241. *
  242. * See [managing focus](/docs/developing/managing-focus) for more information.
  243. */
  244. async setFocus() {
  245. if (this.nativeInput) {
  246. this.nativeInput.focus();
  247. }
  248. }
  249. /**
  250. * Returns the native `<input>` element used under the hood.
  251. */
  252. async getInputElement() {
  253. /**
  254. * If this gets called in certain early lifecycle hooks (ex: Vue onMounted),
  255. * nativeInput won't be defined yet with the custom elements build, so wait for it to load in.
  256. */
  257. if (!this.nativeInput) {
  258. await new Promise((resolve) => componentOnReady(this.el, resolve));
  259. }
  260. return Promise.resolve(this.nativeInput);
  261. }
  262. /**
  263. * Emits an `ionChange` event.
  264. *
  265. * This API should be called for user committed changes.
  266. * This API should not be used for external value changes.
  267. */
  268. emitValueChange(event) {
  269. const { value } = this;
  270. // Checks for both null and undefined values
  271. const newValue = value == null ? value : value.toString();
  272. // Emitting a value change should update the internal state for tracking the focused value
  273. this.focusedValue = newValue;
  274. this.ionChange.emit({ value: newValue, event });
  275. }
  276. /**
  277. * Emits an `ionInput` event.
  278. */
  279. emitInputChange(event) {
  280. const { value } = this;
  281. // Checks for both null and undefined values
  282. const newValue = value == null ? value : value.toString();
  283. this.ionInput.emit({ value: newValue, event });
  284. }
  285. shouldClearOnEdit() {
  286. const { type, clearOnEdit } = this;
  287. return clearOnEdit === undefined ? type === 'password' : clearOnEdit;
  288. }
  289. getValue() {
  290. return typeof this.value === 'number' ? this.value.toString() : (this.value || '').toString();
  291. }
  292. checkClearOnEdit(ev) {
  293. if (!this.shouldClearOnEdit()) {
  294. return;
  295. }
  296. /**
  297. * The following keys do not modify the
  298. * contents of the input. As a result, pressing
  299. * them should not edit the input.
  300. *
  301. * We can't check to see if the value of the input
  302. * was changed because we call checkClearOnEdit
  303. * in a keydown listener, and the key has not yet
  304. * been added to the input.
  305. */
  306. const IGNORED_KEYS = ['Enter', 'Tab', 'Shift', 'Meta', 'Alt', 'Control'];
  307. const pressedIgnoredKey = IGNORED_KEYS.includes(ev.key);
  308. /**
  309. * Clear the input if the control has not been previously cleared during focus.
  310. * Do not clear if the user hitting enter to submit a form.
  311. */
  312. if (!this.didInputClearOnEdit && this.hasValue() && !pressedIgnoredKey) {
  313. this.value = '';
  314. this.emitInputChange(ev);
  315. }
  316. /**
  317. * Pressing an IGNORED_KEYS first and
  318. * then an allowed key will cause the input to not
  319. * be cleared.
  320. */
  321. if (!pressedIgnoredKey) {
  322. this.didInputClearOnEdit = true;
  323. }
  324. }
  325. hasValue() {
  326. return this.getValue().length > 0;
  327. }
  328. /**
  329. * Renders the helper text or error text values
  330. */
  331. renderHintText() {
  332. const { helperText, errorText, helperTextId, errorTextId } = this;
  333. return [
  334. h("div", { id: helperTextId, class: "helper-text" }, helperText),
  335. h("div", { id: errorTextId, class: "error-text" }, errorText),
  336. ];
  337. }
  338. getHintTextID() {
  339. const { el, helperText, errorText, helperTextId, errorTextId } = this;
  340. if (el.classList.contains('ion-touched') && el.classList.contains('ion-invalid') && errorText) {
  341. return errorTextId;
  342. }
  343. if (helperText) {
  344. return helperTextId;
  345. }
  346. return undefined;
  347. }
  348. renderCounter() {
  349. const { counter, maxlength, counterFormatter, value } = this;
  350. if (counter !== true || maxlength === undefined) {
  351. return;
  352. }
  353. return h("div", { class: "counter" }, getCounterText(value, maxlength, counterFormatter));
  354. }
  355. /**
  356. * Responsible for rendering helper text,
  357. * error text, and counter. This element should only
  358. * be rendered if hint text is set or counter is enabled.
  359. */
  360. renderBottomContent() {
  361. const { counter, helperText, errorText, maxlength } = this;
  362. /**
  363. * undefined and empty string values should
  364. * be treated as not having helper/error text.
  365. */
  366. const hasHintText = !!helperText || !!errorText;
  367. const hasCounter = counter === true && maxlength !== undefined;
  368. if (!hasHintText && !hasCounter) {
  369. return;
  370. }
  371. return (h("div", { class: "input-bottom" }, this.renderHintText(), this.renderCounter()));
  372. }
  373. renderLabel() {
  374. const { label } = this;
  375. return (h("div", { class: {
  376. 'label-text-wrapper': true,
  377. 'label-text-wrapper-hidden': !this.hasLabel,
  378. } }, label === undefined ? h("slot", { name: "label" }) : h("div", { class: "label-text" }, label)));
  379. }
  380. /**
  381. * Gets any content passed into the `label` slot,
  382. * not the <slot> definition.
  383. */
  384. get labelSlot() {
  385. return this.el.querySelector('[slot="label"]');
  386. }
  387. /**
  388. * Returns `true` if label content is provided
  389. * either by a prop or a content. If you want
  390. * to get the plaintext value of the label use
  391. * the `labelText` getter instead.
  392. */
  393. get hasLabel() {
  394. return this.label !== undefined || this.labelSlot !== null;
  395. }
  396. /**
  397. * Renders the border container
  398. * when fill="outline".
  399. */
  400. renderLabelContainer() {
  401. const mode = getIonMode(this);
  402. const hasOutlineFill = mode === 'md' && this.fill === 'outline';
  403. if (hasOutlineFill) {
  404. /**
  405. * The outline fill has a special outline
  406. * that appears around the input and the label.
  407. * Certain stacked and floating label placements cause the
  408. * label to translate up and create a "cut out"
  409. * inside of that border by using the notch-spacer element.
  410. */
  411. return [
  412. h("div", { class: "input-outline-container" }, h("div", { class: "input-outline-start" }), h("div", { class: {
  413. 'input-outline-notch': true,
  414. 'input-outline-notch-hidden': !this.hasLabel,
  415. } }, h("div", { class: "notch-spacer", "aria-hidden": "true", ref: (el) => (this.notchSpacerEl = el) }, this.label)), h("div", { class: "input-outline-end" })),
  416. this.renderLabel(),
  417. ];
  418. }
  419. /**
  420. * If not using the outline style,
  421. * we can render just the label.
  422. */
  423. return this.renderLabel();
  424. }
  425. render() {
  426. const { disabled, fill, readonly, shape, inputId, labelPlacement, el, hasFocus, clearInputIcon } = this;
  427. const mode = getIonMode(this);
  428. const value = this.getValue();
  429. const inItem = hostContext('ion-item', this.el);
  430. const shouldRenderHighlight = mode === 'md' && fill !== 'outline' && !inItem;
  431. const defaultClearIcon = mode === 'ios' ? closeCircle : closeSharp;
  432. const clearIconData = clearInputIcon !== null && clearInputIcon !== void 0 ? clearInputIcon : defaultClearIcon;
  433. const hasValue = this.hasValue();
  434. const hasStartEndSlots = el.querySelector('[slot="start"], [slot="end"]') !== null;
  435. /**
  436. * If the label is stacked, it should always sit above the input.
  437. * For floating labels, the label should move above the input if
  438. * the input has a value, is focused, or has anything in either
  439. * the start or end slot.
  440. *
  441. * If there is content in the start slot, the label would overlap
  442. * it if not forced to float. This is also applied to the end slot
  443. * because with the default or solid fills, the input is not
  444. * vertically centered in the container, but the label is. This
  445. * causes the slots and label to appear vertically offset from each
  446. * other when the label isn't floating above the input. This doesn't
  447. * apply to the outline fill, but this was not accounted for to keep
  448. * things consistent.
  449. *
  450. * TODO(FW-5592): Remove hasStartEndSlots condition
  451. */
  452. const labelShouldFloat = labelPlacement === 'stacked' || (labelPlacement === 'floating' && (hasValue || hasFocus || hasStartEndSlots));
  453. return (h(Host, { key: '41b2526627e7d2773a80f011b123284203a71ca0', class: createColorClasses(this.color, {
  454. [mode]: true,
  455. 'has-value': hasValue,
  456. 'has-focus': hasFocus,
  457. 'label-floating': labelShouldFloat,
  458. [`input-fill-${fill}`]: fill !== undefined,
  459. [`input-shape-${shape}`]: shape !== undefined,
  460. [`input-label-placement-${labelPlacement}`]: true,
  461. 'in-item': inItem,
  462. 'in-item-color': hostContext('ion-item.ion-color', this.el),
  463. 'input-disabled': disabled,
  464. }) }, h("label", { key: '9ab078363e32528102b441ad1791d83f86fdcbdc', class: "input-wrapper", htmlFor: inputId, onClick: this.onLabelClick }, this.renderLabelContainer(), h("div", { key: 'e34b594980ec62e4c618e827fadf7669a39ad0d8', class: "native-wrapper", onClick: this.onLabelClick }, h("slot", { key: '12dc04ead5502e9e5736240e918bf9331bf7b5d9', name: "start" }), h("input", Object.assign({ key: 'df356eb4ced23109b2c0242f36dc043aba8782d6', class: "native-input", ref: (input) => (this.nativeInput = input), id: inputId, disabled: disabled, autoCapitalize: this.autocapitalize, autoComplete: this.autocomplete, autoCorrect: this.autocorrect, autoFocus: this.autofocus, enterKeyHint: this.enterkeyhint, inputMode: this.inputmode, min: this.min, max: this.max, minLength: this.minlength, maxLength: this.maxlength, multiple: this.multiple, name: this.name, pattern: this.pattern, placeholder: this.placeholder || '', readOnly: readonly, required: this.required, spellcheck: this.spellcheck, step: this.step, type: this.type, value: value, onInput: this.onInput, onChange: this.onChange, onBlur: this.onBlur, onFocus: this.onFocus, onKeyDown: this.onKeydown, onCompositionstart: this.onCompositionStart, onCompositionend: this.onCompositionEnd, "aria-describedby": this.getHintTextID(), "aria-invalid": this.getHintTextID() === this.errorTextId }, this.inheritedAttributes)), this.clearInput && !readonly && !disabled && (h("button", { key: 'aa7cb47ac287140a68c5cb0ee9359abaa611e21b', "aria-label": "reset", type: "button", class: "input-clear-icon", onPointerDown: (ev) => {
  465. /**
  466. * This prevents mobile browsers from
  467. * blurring the input when the clear
  468. * button is activated.
  469. */
  470. ev.preventDefault();
  471. }, onFocusin: (ev) => {
  472. /**
  473. * Prevent the focusin event from bubbling otherwise it will cause the focusin
  474. * event listener in scroll assist to fire. When this fires, focus will be moved
  475. * back to the input even if the clear button was never tapped. This poses issues
  476. * for screen readers as it means users would be unable to swipe past the clear button.
  477. */
  478. ev.stopPropagation();
  479. }, onClick: this.clearTextInput }, h("ion-icon", { key: 'cd03e46b97299d9db5cedf81944ae9bbe72bacdc', "aria-hidden": "true", icon: clearIconData }))), h("slot", { key: 'de36b79a89c4b413beba22e8a74c53dbf57a84ab', name: "end" })), shouldRenderHighlight && h("div", { key: 'f088509073845bf767ea7ccfde1e917e1cf93cc1', class: "input-highlight" })), this.renderBottomContent()));
  480. }
  481. get el() { return this; }
  482. static get watchers() { return {
  483. "debounce": ["debounceChanged"],
  484. "type": ["onTypeChange"],
  485. "value": ["valueChanged"],
  486. "dir": ["onDirChanged"]
  487. }; }
  488. static get style() { return {
  489. ios: IonInputIosStyle0,
  490. md: IonInputMdStyle0
  491. }; }
  492. }, [38, "ion-input", {
  493. "color": [513],
  494. "autocapitalize": [1],
  495. "autocomplete": [1],
  496. "autocorrect": [1],
  497. "autofocus": [4],
  498. "clearInput": [4, "clear-input"],
  499. "clearInputIcon": [1, "clear-input-icon"],
  500. "clearOnEdit": [4, "clear-on-edit"],
  501. "counter": [4],
  502. "counterFormatter": [16],
  503. "debounce": [2],
  504. "disabled": [516],
  505. "enterkeyhint": [1],
  506. "errorText": [1, "error-text"],
  507. "fill": [1],
  508. "inputmode": [1],
  509. "helperText": [1, "helper-text"],
  510. "label": [1],
  511. "labelPlacement": [1, "label-placement"],
  512. "max": [8],
  513. "maxlength": [2],
  514. "min": [8],
  515. "minlength": [2],
  516. "multiple": [4],
  517. "name": [1],
  518. "pattern": [1],
  519. "placeholder": [1],
  520. "readonly": [516],
  521. "required": [4],
  522. "shape": [1],
  523. "spellcheck": [4],
  524. "step": [1],
  525. "type": [1],
  526. "value": [1032],
  527. "hasFocus": [32],
  528. "setFocus": [64],
  529. "getInputElement": [64]
  530. }, [[2, "click", "onClickCapture"]], {
  531. "debounce": ["debounceChanged"],
  532. "type": ["onTypeChange"],
  533. "value": ["valueChanged"],
  534. "dir": ["onDirChanged"]
  535. }]);
  536. let inputIds = 0;
  537. function defineCustomElement$1() {
  538. if (typeof customElements === "undefined") {
  539. return;
  540. }
  541. const components = ["ion-input", "ion-icon"];
  542. components.forEach(tagName => { switch (tagName) {
  543. case "ion-input":
  544. if (!customElements.get(tagName)) {
  545. customElements.define(tagName, Input);
  546. }
  547. break;
  548. case "ion-icon":
  549. if (!customElements.get(tagName)) {
  550. defineCustomElement$2();
  551. }
  552. break;
  553. } });
  554. }
  555. const IonInput = Input;
  556. const defineCustomElement = defineCustomElement$1;
  557. export { IonInput, defineCustomElement };