ion-select.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { proxyCustomElement, HTMLElement, createEvent, h, Host, forceUpdate } from '@stencil/core/internal/client';
  5. import { c as createNotchController } from './notch-controller.js';
  6. import { i as isOptionSelected, c as compareOptions, d as defineCustomElement$8 } from './radio.js';
  7. import { d as inheritAttributes, e as renderHiddenInput, f as focusVisibleElement } from './helpers.js';
  8. import { a as printIonWarning } from './index4.js';
  9. import { c as popoverController, b as actionSheetController, a as alertController, m as modalController } from './overlays.js';
  10. import { i as isRTL } from './dir.js';
  11. import { h as hostContext, c as createColorClasses } from './theme.js';
  12. import { w as watchForOptions } from './watch-options.js';
  13. import { v as chevronExpand, h as caretDownSharp } from './index7.js';
  14. import { b as getIonMode } from './ionic-global.js';
  15. import { d as defineCustomElement$n } from './action-sheet.js';
  16. import { d as defineCustomElement$m } from './alert.js';
  17. import { d as defineCustomElement$l } from './backdrop.js';
  18. import { d as defineCustomElement$k } from './button.js';
  19. import { d as defineCustomElement$j } from './buttons.js';
  20. import { d as defineCustomElement$i } from './checkbox.js';
  21. import { d as defineCustomElement$h } from './content.js';
  22. import { d as defineCustomElement$g } from './header.js';
  23. import { d as defineCustomElement$f } from './icon.js';
  24. import { d as defineCustomElement$e } from './item.js';
  25. import { d as defineCustomElement$d } from './label.js';
  26. import { d as defineCustomElement$c } from './list.js';
  27. import { d as defineCustomElement$b } from './list-header.js';
  28. import { d as defineCustomElement$a } from './modal.js';
  29. import { d as defineCustomElement$9 } from './popover.js';
  30. import { d as defineCustomElement$7 } from './radio-group.js';
  31. import { d as defineCustomElement$6 } from './ripple-effect.js';
  32. import { d as defineCustomElement$5 } from './select-modal.js';
  33. import { d as defineCustomElement$4 } from './select-popover.js';
  34. import { d as defineCustomElement$3 } from './title.js';
  35. import { d as defineCustomElement$2 } from './toolbar.js';
  36. const selectIosCss = ":host{--padding-top:0px;--padding-end:0px;--padding-bottom:0px;--padding-start:0px;--placeholder-color:currentColor;--placeholder-opacity:var(--ion-placeholder-opacity, 0.6);--background:transparent;--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;font-family:var(--ion-font-family, inherit);white-space:nowrap;cursor:pointer;z-index:2}:host(.select-label-placement-floating),:host(.select-label-placement-stacked){min-height:56px}:host(.ion-color){--highlight-color-focused:var(--ion-color-base)}:host(.in-item){-ms-flex:1 1 0px;flex:1 1 0}:host(.select-disabled){pointer-events:none}:host(.has-focus) button{border:2px solid #5e9ed6}:host([slot=start]),:host([slot=end]){-ms-flex:initial;flex:initial;width:auto}.select-placeholder{color:var(--placeholder-color);opacity:var(--placeholder-opacity)}button{position:absolute;top:0;left:0;right:0;bottom:0;width:100%;height:100%;margin:0;padding:0;border:0;outline:0;clip:rect(0 0 0 0);opacity:0;overflow:hidden;-webkit-appearance:none;-moz-appearance:none}.select-icon{-webkit-margin-start:4px;margin-inline-start:4px;-webkit-margin-end:0;margin-inline-end:0;margin-top:0;margin-bottom:0;position:relative;-ms-flex-negative:0;flex-shrink:0}:host(.in-item-color) .select-icon{color:inherit}:host(.select-label-placement-stacked) .select-icon,:host(.select-label-placement-floating) .select-icon{position:absolute;height:100%}:host(.select-ltr.select-label-placement-stacked) .select-icon,:host(.select-ltr.select-label-placement-floating) .select-icon{right:var(--padding-end, 0)}:host(.select-rtl.select-label-placement-stacked) .select-icon,:host(.select-rtl.select-label-placement-floating) .select-icon{left:var(--padding-start, 0)}.select-text{-ms-flex:1;flex:1;min-width:16px;font-size:inherit;text-overflow:ellipsis;white-space:inherit;overflow:hidden}.select-wrapper{-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:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;height:inherit;min-height:inherit;-webkit-transition:background-color 15ms linear;transition:background-color 15ms linear;background:var(--background);line-height:normal;cursor:inherit;-webkit-box-sizing:border-box;box-sizing:border-box}.select-wrapper .select-placeholder{-webkit-transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1)}.select-wrapper-inner{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;overflow:hidden}:host(.select-label-placement-stacked) .select-wrapper-inner,:host(.select-label-placement-floating) .select-wrapper-inner{-ms-flex-positive:1;flex-grow:1}:host(.ion-touched.ion-invalid){--highlight-color:var(--highlight-color-invalid)}:host(.ion-valid){--highlight-color:var(--highlight-color-valid)}.select-bottom{-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}:host(.has-focus.ion-valid),:host(.select-expanded.ion-valid),:host(.ion-touched.ion-invalid),:host(.select-expanded.ion-touched.ion-invalid){--border-color:var(--highlight-color)}.select-bottom .error-text{display:none;color:var(--highlight-color-invalid)}.select-bottom .helper-text{display:block;color:var(--ion-color-step-700, var(--ion-text-color-step-300, #4d4d4d))}:host(.ion-touched.ion-invalid) .select-bottom .error-text{display:block}:host(.ion-touched.ion-invalid) .select-bottom .helper-text{display:none}.label-text-wrapper{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,::slotted([slot=label]){text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.label-text-wrapper-hidden,.select-outline-notch-hidden{display:none}.native-wrapper{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-webkit-transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);overflow:hidden}:host(.select-justify-space-between) .select-wrapper{-ms-flex-pack:justify;justify-content:space-between}:host(.select-justify-start) .select-wrapper{-ms-flex-pack:start;justify-content:start}:host(.select-justify-end) .select-wrapper{-ms-flex-pack:end;justify-content:end}:host(.select-label-placement-start) .select-wrapper{-ms-flex-direction:row;flex-direction:row}:host(.select-label-placement-start) .label-text-wrapper{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}:host(.select-label-placement-end) .select-wrapper{-ms-flex-direction:row-reverse;flex-direction:row-reverse}:host(.select-label-placement-end) .label-text-wrapper{-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0;margin-top:0;margin-bottom:0}:host(.select-label-placement-fixed) .label-text-wrapper{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}:host(.select-label-placement-fixed) .label-text-wrapper{-ms-flex:0 0 100px;flex:0 0 100px;width:100px;min-width:100px;max-width:200px}:host(.select-label-placement-stacked) .select-wrapper,:host(.select-label-placement-floating) .select-wrapper{-ms-flex-direction:column;flex-direction:column;-ms-flex-align:start;align-items:start}:host(.select-label-placement-stacked) .label-text-wrapper,:host(.select-label-placement-floating) .label-text-wrapper{max-width:100%}:host(.select-ltr.select-label-placement-stacked) .label-text-wrapper,:host(.select-ltr.select-label-placement-floating) .label-text-wrapper{-webkit-transform-origin:left top;transform-origin:left top}:host(.select-rtl.select-label-placement-stacked) .label-text-wrapper,:host(.select-rtl.select-label-placement-floating) .label-text-wrapper{-webkit-transform-origin:right top;transform-origin:right top}:host(.select-label-placement-stacked) .native-wrapper,:host(.select-label-placement-floating) .native-wrapper{margin-left:0;margin-right:0;margin-top:1px;margin-bottom:0;-ms-flex-positive:1;flex-grow:1;width:100%}:host(.select-label-placement-floating) .label-text-wrapper{-webkit-transform:translateY(100%) scale(1);transform:translateY(100%) scale(1)}:host(.select-label-placement-floating:not(.label-floating)) .native-wrapper .select-placeholder{opacity:0}:host(.select-expanded.select-label-placement-floating) .native-wrapper .select-placeholder,:host(.has-focus.select-label-placement-floating) .native-wrapper .select-placeholder,:host(.has-value.select-label-placement-floating) .native-wrapper .select-placeholder{opacity:1}:host(.label-floating) .label-text-wrapper{-webkit-transform:translateY(50%) scale(0.75);transform:translateY(50%) scale(0.75);max-width:calc(100% / 0.75)}::slotted([slot=start]),::slotted([slot=end]){-ms-flex-negative:0;flex-shrink:0}::slotted([slot=start]:last-of-type){-webkit-margin-end:16px;margin-inline-end:16px;-webkit-margin-start:0;margin-inline-start:0}::slotted([slot=end]:first-of-type){-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0}:host{--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}.select-icon{width:1.125rem;height:1.125rem;color:var(--ion-color-step-650, var(--ion-text-color-step-350, #595959))}:host(.select-label-placement-stacked) .select-wrapper-inner,:host(.select-label-placement-floating) .select-wrapper-inner{width:calc(100% - 1.125rem - 4px)}:host(.select-disabled){opacity:0.3}::slotted(ion-button[slot=start].button-has-icon-only),::slotted(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}";
  37. const IonSelectIosStyle0 = selectIosCss;
  38. const selectMdCss = ":host{--padding-top:0px;--padding-end:0px;--padding-bottom:0px;--padding-start:0px;--placeholder-color:currentColor;--placeholder-opacity:var(--ion-placeholder-opacity, 0.6);--background:transparent;--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;font-family:var(--ion-font-family, inherit);white-space:nowrap;cursor:pointer;z-index:2}:host(.select-label-placement-floating),:host(.select-label-placement-stacked){min-height:56px}:host(.ion-color){--highlight-color-focused:var(--ion-color-base)}:host(.in-item){-ms-flex:1 1 0px;flex:1 1 0}:host(.select-disabled){pointer-events:none}:host(.has-focus) button{border:2px solid #5e9ed6}:host([slot=start]),:host([slot=end]){-ms-flex:initial;flex:initial;width:auto}.select-placeholder{color:var(--placeholder-color);opacity:var(--placeholder-opacity)}button{position:absolute;top:0;left:0;right:0;bottom:0;width:100%;height:100%;margin:0;padding:0;border:0;outline:0;clip:rect(0 0 0 0);opacity:0;overflow:hidden;-webkit-appearance:none;-moz-appearance:none}.select-icon{-webkit-margin-start:4px;margin-inline-start:4px;-webkit-margin-end:0;margin-inline-end:0;margin-top:0;margin-bottom:0;position:relative;-ms-flex-negative:0;flex-shrink:0}:host(.in-item-color) .select-icon{color:inherit}:host(.select-label-placement-stacked) .select-icon,:host(.select-label-placement-floating) .select-icon{position:absolute;height:100%}:host(.select-ltr.select-label-placement-stacked) .select-icon,:host(.select-ltr.select-label-placement-floating) .select-icon{right:var(--padding-end, 0)}:host(.select-rtl.select-label-placement-stacked) .select-icon,:host(.select-rtl.select-label-placement-floating) .select-icon{left:var(--padding-start, 0)}.select-text{-ms-flex:1;flex:1;min-width:16px;font-size:inherit;text-overflow:ellipsis;white-space:inherit;overflow:hidden}.select-wrapper{-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:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;height:inherit;min-height:inherit;-webkit-transition:background-color 15ms linear;transition:background-color 15ms linear;background:var(--background);line-height:normal;cursor:inherit;-webkit-box-sizing:border-box;box-sizing:border-box}.select-wrapper .select-placeholder{-webkit-transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1)}.select-wrapper-inner{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;overflow:hidden}:host(.select-label-placement-stacked) .select-wrapper-inner,:host(.select-label-placement-floating) .select-wrapper-inner{-ms-flex-positive:1;flex-grow:1}:host(.ion-touched.ion-invalid){--highlight-color:var(--highlight-color-invalid)}:host(.ion-valid){--highlight-color:var(--highlight-color-valid)}.select-bottom{-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}:host(.has-focus.ion-valid),:host(.select-expanded.ion-valid),:host(.ion-touched.ion-invalid),:host(.select-expanded.ion-touched.ion-invalid){--border-color:var(--highlight-color)}.select-bottom .error-text{display:none;color:var(--highlight-color-invalid)}.select-bottom .helper-text{display:block;color:var(--ion-color-step-700, var(--ion-text-color-step-300, #4d4d4d))}:host(.ion-touched.ion-invalid) .select-bottom .error-text{display:block}:host(.ion-touched.ion-invalid) .select-bottom .helper-text{display:none}.label-text-wrapper{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,::slotted([slot=label]){text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.label-text-wrapper-hidden,.select-outline-notch-hidden{display:none}.native-wrapper{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-webkit-transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);overflow:hidden}:host(.select-justify-space-between) .select-wrapper{-ms-flex-pack:justify;justify-content:space-between}:host(.select-justify-start) .select-wrapper{-ms-flex-pack:start;justify-content:start}:host(.select-justify-end) .select-wrapper{-ms-flex-pack:end;justify-content:end}:host(.select-label-placement-start) .select-wrapper{-ms-flex-direction:row;flex-direction:row}:host(.select-label-placement-start) .label-text-wrapper{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}:host(.select-label-placement-end) .select-wrapper{-ms-flex-direction:row-reverse;flex-direction:row-reverse}:host(.select-label-placement-end) .label-text-wrapper{-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0;margin-top:0;margin-bottom:0}:host(.select-label-placement-fixed) .label-text-wrapper{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:16px;margin-inline-end:16px;margin-top:0;margin-bottom:0}:host(.select-label-placement-fixed) .label-text-wrapper{-ms-flex:0 0 100px;flex:0 0 100px;width:100px;min-width:100px;max-width:200px}:host(.select-label-placement-stacked) .select-wrapper,:host(.select-label-placement-floating) .select-wrapper{-ms-flex-direction:column;flex-direction:column;-ms-flex-align:start;align-items:start}:host(.select-label-placement-stacked) .label-text-wrapper,:host(.select-label-placement-floating) .label-text-wrapper{max-width:100%}:host(.select-ltr.select-label-placement-stacked) .label-text-wrapper,:host(.select-ltr.select-label-placement-floating) .label-text-wrapper{-webkit-transform-origin:left top;transform-origin:left top}:host(.select-rtl.select-label-placement-stacked) .label-text-wrapper,:host(.select-rtl.select-label-placement-floating) .label-text-wrapper{-webkit-transform-origin:right top;transform-origin:right top}:host(.select-label-placement-stacked) .native-wrapper,:host(.select-label-placement-floating) .native-wrapper{margin-left:0;margin-right:0;margin-top:1px;margin-bottom:0;-ms-flex-positive:1;flex-grow:1;width:100%}:host(.select-label-placement-floating) .label-text-wrapper{-webkit-transform:translateY(100%) scale(1);transform:translateY(100%) scale(1)}:host(.select-label-placement-floating:not(.label-floating)) .native-wrapper .select-placeholder{opacity:0}:host(.select-expanded.select-label-placement-floating) .native-wrapper .select-placeholder,:host(.has-focus.select-label-placement-floating) .native-wrapper .select-placeholder,:host(.has-value.select-label-placement-floating) .native-wrapper .select-placeholder{opacity:1}:host(.label-floating) .label-text-wrapper{-webkit-transform:translateY(50%) scale(0.75);transform:translateY(50%) scale(0.75);max-width:calc(100% / 0.75)}::slotted([slot=start]),::slotted([slot=end]){-ms-flex-negative:0;flex-shrink:0}::slotted([slot=start]:last-of-type){-webkit-margin-end:16px;margin-inline-end:16px;-webkit-margin-start:0;margin-inline-start:0}::slotted([slot=end]:first-of-type){-webkit-margin-start:16px;margin-inline-start:16px;-webkit-margin-end:0;margin-inline-end:0}:host(.select-fill-solid){--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}:host(.select-fill-solid) .select-wrapper{border-bottom:var(--border-width) var(--border-style) var(--border-color)}:host(.select-expanded.select-fill-solid.ion-valid),:host(.has-focus.select-fill-solid.ion-valid),:host(.select-fill-solid.ion-touched.ion-invalid){--border-color:var(--highlight-color)}:host(.select-fill-solid) .select-bottom{border-top:none}@media (any-hover: hover){:host(.select-fill-solid: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))}}:host(.select-fill-solid.select-expanded),:host(.select-fill-solid.has-focus){--background:var(--ion-color-step-150, var(--ion-background-color-step-150, #d9d9d9));--border-color:var(--highlight-color)}:host(.select-fill-solid) .select-wrapper{border-start-start-radius:var(--border-radius);border-start-end-radius:var(--border-radius);border-end-end-radius:0px;border-end-start-radius:0px}:host(.label-floating.select-fill-solid) .label-text-wrapper{max-width:calc(100% / 0.75)}:host(.in-item.select-expanded.select-fill-solid) .select-wrapper .select-icon,:host(.in-item.has-focus.select-fill-solid) .select-wrapper .select-icon,:host(.in-item.has-focus.ion-valid.select-fill-solid) .select-wrapper .select-icon,:host(.in-item.ion-touched.ion-invalid.select-fill-solid) .select-wrapper .select-icon{color:var(--highlight-color)}:host(.select-fill-outline){--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}:host(.select-fill-outline.select-shape-round){--border-radius:28px;--padding-start:32px;--padding-end:32px}:host(.has-focus.select-fill-outline.ion-valid),:host(.select-fill-outline.ion-touched.ion-invalid){--border-color:var(--highlight-color)}@media (any-hover: hover){:host(.select-fill-outline:hover){--border-color:var(--ion-color-step-750, var(--ion-background-color-step-750, #404040))}}:host(.select-fill-outline.select-expanded),:host(.select-fill-outline.has-focus){--border-width:var(--highlight-height);--border-color:var(--highlight-color)}:host(.select-fill-outline) .select-bottom{border-top:none}:host(.select-fill-outline) .select-wrapper{border-bottom:none}:host(.select-ltr.select-fill-outline.select-label-placement-stacked) .label-text-wrapper,:host(.select-ltr.select-fill-outline.select-label-placement-floating) .label-text-wrapper{-webkit-transform-origin:left top;transform-origin:left top}:host(.select-rtl.select-fill-outline.select-label-placement-stacked) .label-text-wrapper,:host(.select-rtl.select-fill-outline.select-label-placement-floating) .label-text-wrapper{-webkit-transform-origin:right top;transform-origin:right top}:host(.select-fill-outline.select-label-placement-stacked) .label-text-wrapper,:host(.select-fill-outline.select-label-placement-floating) .label-text-wrapper{position:absolute;max-width:calc(100% - var(--padding-start) - var(--padding-end))}:host(.select-fill-outline) .label-text-wrapper{position:relative;z-index:1}:host(.label-floating.select-fill-outline) .label-text-wrapper{-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)}:host(.select-fill-outline.select-label-placement-stacked) select,:host(.select-fill-outline.select-label-placement-floating) select{margin-left:0;margin-right:0;margin-top:6px;margin-bottom:6px}:host(.select-fill-outline) .select-outline-container{left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:absolute;width:100%;height:100%}:host(.select-fill-outline) .select-outline-start,:host(.select-fill-outline) .select-outline-end{pointer-events:none}:host(.select-fill-outline) .select-outline-start,:host(.select-fill-outline) .select-outline-notch,:host(.select-fill-outline) .select-outline-end{border-top:var(--border-width) var(--border-style) var(--border-color);border-bottom:var(--border-width) var(--border-style) var(--border-color);-webkit-box-sizing:border-box;box-sizing:border-box}:host(.select-fill-outline) .select-outline-notch{max-width:calc(100% - var(--padding-start) - var(--padding-end))}:host(.select-fill-outline) .notch-spacer{-webkit-padding-end:8px;padding-inline-end:8px;font-size:calc(1em * 0.75);opacity:0;pointer-events:none}:host(.select-fill-outline) .select-outline-start{-webkit-border-start:var(--border-width) var(--border-style) var(--border-color);border-inline-start:var(--border-width) var(--border-style) var(--border-color)}:host(.select-fill-outline) .select-outline-start{border-start-start-radius:var(--border-radius);border-start-end-radius:0px;border-end-end-radius:0px;border-end-start-radius:var(--border-radius)}:host(.select-fill-outline) .select-outline-start{width:calc(var(--padding-start) - 4px)}:host(.select-fill-outline) .select-outline-end{-webkit-border-end:var(--border-width) var(--border-style) var(--border-color);border-inline-end:var(--border-width) var(--border-style) var(--border-color)}:host(.select-fill-outline) .select-outline-end{border-start-start-radius:0px;border-start-end-radius:var(--border-radius);border-end-end-radius:var(--border-radius);border-end-start-radius:0px}:host(.select-fill-outline) .select-outline-end{-ms-flex-positive:1;flex-grow:1}:host(.label-floating.select-fill-outline) .select-outline-notch{border-top:none}:host(.in-item.select-expanded.select-fill-outline) .select-wrapper .select-icon,:host(.in-item.has-focus.select-fill-outline) .select-wrapper .select-icon,:host(.in-item.has-focus.ion-valid.select-fill-outline) .select-wrapper .select-icon,:host(.in-item.ion-touched.ion-invalid.select-fill-outline) .select-wrapper .select-icon{color:var(--highlight-color)}:host{--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}:host(.select-label-placement-floating.select-expanded) .label-text-wrapper,:host(.select-label-placement-floating.has-focus) .label-text-wrapper,:host(.select-label-placement-stacked.select-expanded) .label-text-wrapper,:host(.select-label-placement-stacked.has-focus) .label-text-wrapper{color:var(--highlight-color)}:host(.has-focus.select-label-placement-floating.ion-valid) .label-text-wrapper,:host(.select-label-placement-floating.ion-touched.ion-invalid) .label-text-wrapper,:host(.has-focus.select-label-placement-stacked.ion-valid) .label-text-wrapper,:host(.select-label-placement-stacked.ion-touched.ion-invalid) .label-text-wrapper{color:var(--highlight-color)}.select-highlight{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)}.select-highlight{inset-inline-start:0}:host(.select-expanded) .select-highlight,:host(.has-focus) .select-highlight{-webkit-transform:scale(1);transform:scale(1)}:host(.in-item) .select-highlight{bottom:0}:host(.in-item) .select-highlight{inset-inline-start:0}.select-icon{width:0.8125rem;-webkit-transition:-webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);transition:-webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);transition:transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);transition:transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);color:var(--ion-color-step-500, var(--ion-text-color-step-500, gray))}:host(.select-expanded:not(.has-expanded-icon)) .select-icon{-webkit-transform:rotate(180deg);transform:rotate(180deg)}:host(.in-item.select-expanded) .select-wrapper .select-icon,:host(.in-item.has-focus) .select-wrapper .select-icon,:host(.in-item.has-focus.ion-valid) .select-wrapper .select-icon,:host(.in-item.ion-touched.ion-invalid) .select-wrapper .select-icon{color:var(--ion-color-step-500, var(--ion-text-color-step-500, gray))}:host(.select-expanded) .select-wrapper .select-icon,:host(.has-focus.ion-valid) .select-wrapper .select-icon,:host(.ion-touched.ion-invalid) .select-wrapper .select-icon,:host(.has-focus) .select-wrapper .select-icon{color:var(--highlight-color)}:host(.select-shape-round){--border-radius:16px}:host(.select-label-placement-stacked) .select-wrapper-inner,:host(.select-label-placement-floating) .select-wrapper-inner{width:calc(100% - 0.8125rem - 4px)}:host(.select-disabled){opacity:0.38}::slotted(ion-button[slot=start].button-has-icon-only),::slotted(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}";
  39. const IonSelectMdStyle0 = selectMdCss;
  40. const Select = /*@__PURE__*/ proxyCustomElement(class Select extends HTMLElement {
  41. constructor() {
  42. super();
  43. this.__registerHost();
  44. this.__attachShadow();
  45. this.ionChange = createEvent(this, "ionChange", 7);
  46. this.ionCancel = createEvent(this, "ionCancel", 7);
  47. this.ionDismiss = createEvent(this, "ionDismiss", 7);
  48. this.ionFocus = createEvent(this, "ionFocus", 7);
  49. this.ionBlur = createEvent(this, "ionBlur", 7);
  50. this.ionStyle = createEvent(this, "ionStyle", 7);
  51. this.inputId = `ion-sel-${selectIds++}`;
  52. this.helperTextId = `${this.inputId}-helper-text`;
  53. this.errorTextId = `${this.inputId}-error-text`;
  54. this.inheritedAttributes = {};
  55. this.onClick = (ev) => {
  56. const target = ev.target;
  57. const closestSlot = target.closest('[slot="start"], [slot="end"]');
  58. if (target === this.el || closestSlot === null) {
  59. this.setFocus();
  60. this.open(ev);
  61. }
  62. else {
  63. /**
  64. * Prevent clicks to the start/end slots from opening the select.
  65. * We ensure the target isn't this element in case the select is slotted
  66. * in, for example, an item. This would prevent the select from ever
  67. * being opened since the element itself has slot="start"/"end".
  68. *
  69. * Clicking a slotted element also causes a click
  70. * on the <label> element (since it wraps the slots).
  71. * Clicking <label> dispatches another click event on
  72. * the native form control that then bubbles up to this
  73. * listener. This additional event targets the host
  74. * element, so the select overlay is opened.
  75. *
  76. * When the slotted elements are clicked (and therefore
  77. * the ancestor <label> element) we want to prevent the label
  78. * from dispatching another click event.
  79. *
  80. * Do not call stopPropagation() because this will cause
  81. * click handlers on the slotted elements to never fire in React.
  82. * When developers do onClick in React a native "click" listener
  83. * is added on the root element, not the slotted element. When that
  84. * native click listener fires, React then dispatches the synthetic
  85. * click event on the slotted element. However, if stopPropagation
  86. * is called then the native click event will never bubble up
  87. * to the root element.
  88. */
  89. ev.preventDefault();
  90. }
  91. };
  92. this.onFocus = () => {
  93. this.hasFocus = true;
  94. this.ionFocus.emit();
  95. };
  96. this.onBlur = () => {
  97. this.hasFocus = false;
  98. this.ionBlur.emit();
  99. };
  100. /**
  101. * Stops propagation when the label is clicked,
  102. * otherwise, two clicks will be triggered.
  103. */
  104. this.onLabelClick = (ev) => {
  105. // Only stop propagation if the click was directly on the label
  106. // and not on the input or other child elements
  107. if (ev.target === ev.currentTarget) {
  108. ev.stopPropagation();
  109. }
  110. };
  111. this.isExpanded = false;
  112. this.hasFocus = false;
  113. this.cancelText = 'Cancel';
  114. this.color = undefined;
  115. this.compareWith = undefined;
  116. this.disabled = false;
  117. this.fill = undefined;
  118. this.errorText = undefined;
  119. this.helperText = undefined;
  120. this.interface = 'alert';
  121. this.interfaceOptions = {};
  122. this.justify = undefined;
  123. this.label = undefined;
  124. this.labelPlacement = 'start';
  125. this.multiple = false;
  126. this.name = this.inputId;
  127. this.okText = 'OK';
  128. this.placeholder = undefined;
  129. this.selectedText = undefined;
  130. this.toggleIcon = undefined;
  131. this.expandedIcon = undefined;
  132. this.shape = undefined;
  133. this.value = undefined;
  134. this.required = false;
  135. }
  136. styleChanged() {
  137. this.emitStyle();
  138. }
  139. setValue(value) {
  140. this.value = value;
  141. this.ionChange.emit({ value });
  142. }
  143. async connectedCallback() {
  144. const { el } = this;
  145. this.notchController = createNotchController(el, () => this.notchSpacerEl, () => this.labelSlot);
  146. this.updateOverlayOptions();
  147. this.emitStyle();
  148. this.mutationO = watchForOptions(this.el, 'ion-select-option', async () => {
  149. this.updateOverlayOptions();
  150. /**
  151. * We need to re-render the component
  152. * because one of the new ion-select-option
  153. * elements may match the value. In this case,
  154. * the rendered selected text should be updated.
  155. */
  156. forceUpdate(this);
  157. });
  158. }
  159. componentWillLoad() {
  160. this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);
  161. }
  162. componentDidLoad() {
  163. /**
  164. * If any of the conditions that trigger the styleChanged callback
  165. * are met on component load, it is possible the event emitted
  166. * prior to a parent web component registering an event listener.
  167. *
  168. * To ensure the parent web component receives the event, we
  169. * emit the style event again after the component has loaded.
  170. *
  171. * This is often seen in Angular with the `dist` output target.
  172. */
  173. this.emitStyle();
  174. }
  175. disconnectedCallback() {
  176. if (this.mutationO) {
  177. this.mutationO.disconnect();
  178. this.mutationO = undefined;
  179. }
  180. if (this.notchController) {
  181. this.notchController.destroy();
  182. this.notchController = undefined;
  183. }
  184. }
  185. /**
  186. * Open the select overlay. The overlay is either an alert, action sheet, or popover,
  187. * depending on the `interface` property on the `ion-select`.
  188. *
  189. * @param event The user interface event that called the open.
  190. */
  191. async open(event) {
  192. if (this.disabled || this.isExpanded) {
  193. return undefined;
  194. }
  195. this.isExpanded = true;
  196. const overlay = (this.overlay = await this.createOverlay(event));
  197. // Add logic to scroll selected item into view before presenting
  198. const scrollSelectedIntoView = () => {
  199. const indexOfSelected = this.childOpts.findIndex((o) => o.value === this.value);
  200. if (indexOfSelected > -1) {
  201. const selectedItem = overlay.querySelector(`.select-interface-option:nth-child(${indexOfSelected + 1})`);
  202. if (selectedItem) {
  203. /**
  204. * Browsers such as Firefox do not
  205. * correctly delegate focus when manually
  206. * focusing an element with delegatesFocus.
  207. * We work around this by manually focusing
  208. * the interactive element.
  209. * ion-radio and ion-checkbox are the only
  210. * elements that ion-select-popover uses, so
  211. * we only need to worry about those two components
  212. * when focusing.
  213. */
  214. const interactiveEl = selectedItem.querySelector('ion-radio, ion-checkbox');
  215. if (interactiveEl) {
  216. selectedItem.scrollIntoView({ block: 'nearest' });
  217. // Needs to be called before `focusVisibleElement` to prevent issue with focus event bubbling
  218. // and removing `ion-focused` style
  219. interactiveEl.setFocus();
  220. }
  221. focusVisibleElement(selectedItem);
  222. }
  223. }
  224. else {
  225. /**
  226. * If no value is set then focus the first enabled option.
  227. */
  228. const firstEnabledOption = overlay.querySelector('ion-radio:not(.radio-disabled), ion-checkbox:not(.checkbox-disabled)');
  229. if (firstEnabledOption) {
  230. /**
  231. * Focus the option for the same reason as we do above.
  232. *
  233. * Needs to be called before `focusVisibleElement` to prevent issue with focus event bubbling
  234. * and removing `ion-focused` style
  235. */
  236. firstEnabledOption.setFocus();
  237. focusVisibleElement(firstEnabledOption.closest('ion-item'));
  238. }
  239. }
  240. };
  241. // For modals and popovers, we can scroll before they're visible
  242. if (this.interface === 'modal') {
  243. overlay.addEventListener('ionModalWillPresent', scrollSelectedIntoView, { once: true });
  244. }
  245. else if (this.interface === 'popover') {
  246. overlay.addEventListener('ionPopoverWillPresent', scrollSelectedIntoView, { once: true });
  247. }
  248. else {
  249. /**
  250. * For alerts and action sheets, we need to wait a frame after willPresent
  251. * because these overlays don't have their content in the DOM immediately
  252. * when willPresent fires. By waiting a frame, we ensure the content is
  253. * rendered and can be properly scrolled into view.
  254. */
  255. const scrollAfterRender = () => {
  256. requestAnimationFrame(() => {
  257. scrollSelectedIntoView();
  258. });
  259. };
  260. if (this.interface === 'alert') {
  261. overlay.addEventListener('ionAlertWillPresent', scrollAfterRender, { once: true });
  262. }
  263. else if (this.interface === 'action-sheet') {
  264. overlay.addEventListener('ionActionSheetWillPresent', scrollAfterRender, { once: true });
  265. }
  266. }
  267. overlay.onDidDismiss().then(() => {
  268. this.overlay = undefined;
  269. this.isExpanded = false;
  270. this.ionDismiss.emit();
  271. this.setFocus();
  272. });
  273. await overlay.present();
  274. return overlay;
  275. }
  276. createOverlay(ev) {
  277. let selectInterface = this.interface;
  278. if (selectInterface === 'action-sheet' && this.multiple) {
  279. printIonWarning(`[ion-select] - Interface cannot be "${selectInterface}" with a multi-value select. Using the "alert" interface instead.`);
  280. selectInterface = 'alert';
  281. }
  282. if (selectInterface === 'popover' && !ev) {
  283. printIonWarning(`[ion-select] - Interface cannot be a "${selectInterface}" without passing an event. Using the "alert" interface instead.`);
  284. selectInterface = 'alert';
  285. }
  286. if (selectInterface === 'action-sheet') {
  287. return this.openActionSheet();
  288. }
  289. if (selectInterface === 'popover') {
  290. return this.openPopover(ev);
  291. }
  292. if (selectInterface === 'modal') {
  293. return this.openModal();
  294. }
  295. return this.openAlert();
  296. }
  297. updateOverlayOptions() {
  298. const overlay = this.overlay;
  299. if (!overlay) {
  300. return;
  301. }
  302. const childOpts = this.childOpts;
  303. const value = this.value;
  304. switch (this.interface) {
  305. case 'action-sheet':
  306. overlay.buttons = this.createActionSheetButtons(childOpts, value);
  307. break;
  308. case 'popover':
  309. const popover = overlay.querySelector('ion-select-popover');
  310. if (popover) {
  311. popover.options = this.createOverlaySelectOptions(childOpts, value);
  312. }
  313. break;
  314. case 'modal':
  315. const modal = overlay.querySelector('ion-select-modal');
  316. if (modal) {
  317. modal.options = this.createOverlaySelectOptions(childOpts, value);
  318. }
  319. break;
  320. case 'alert':
  321. const inputType = this.multiple ? 'checkbox' : 'radio';
  322. overlay.inputs = this.createAlertInputs(childOpts, inputType, value);
  323. break;
  324. }
  325. }
  326. createActionSheetButtons(data, selectValue) {
  327. const actionSheetButtons = data.map((option) => {
  328. const value = getOptionValue(option);
  329. // Remove hydrated before copying over classes
  330. const copyClasses = Array.from(option.classList)
  331. .filter((cls) => cls !== 'hydrated')
  332. .join(' ');
  333. const optClass = `${OPTION_CLASS} ${copyClasses}`;
  334. return {
  335. role: isOptionSelected(selectValue, value, this.compareWith) ? 'selected' : '',
  336. text: option.textContent,
  337. cssClass: optClass,
  338. handler: () => {
  339. this.setValue(value);
  340. },
  341. };
  342. });
  343. // Add "cancel" button
  344. actionSheetButtons.push({
  345. text: this.cancelText,
  346. role: 'cancel',
  347. handler: () => {
  348. this.ionCancel.emit();
  349. },
  350. });
  351. return actionSheetButtons;
  352. }
  353. createAlertInputs(data, inputType, selectValue) {
  354. const alertInputs = data.map((option) => {
  355. const value = getOptionValue(option);
  356. // Remove hydrated before copying over classes
  357. const copyClasses = Array.from(option.classList)
  358. .filter((cls) => cls !== 'hydrated')
  359. .join(' ');
  360. const optClass = `${OPTION_CLASS} ${copyClasses}`;
  361. return {
  362. type: inputType,
  363. cssClass: optClass,
  364. label: option.textContent || '',
  365. value,
  366. checked: isOptionSelected(selectValue, value, this.compareWith),
  367. disabled: option.disabled,
  368. };
  369. });
  370. return alertInputs;
  371. }
  372. createOverlaySelectOptions(data, selectValue) {
  373. const popoverOptions = data.map((option) => {
  374. const value = getOptionValue(option);
  375. // Remove hydrated before copying over classes
  376. const copyClasses = Array.from(option.classList)
  377. .filter((cls) => cls !== 'hydrated')
  378. .join(' ');
  379. const optClass = `${OPTION_CLASS} ${copyClasses}`;
  380. return {
  381. text: option.textContent || '',
  382. cssClass: optClass,
  383. value,
  384. checked: isOptionSelected(selectValue, value, this.compareWith),
  385. disabled: option.disabled,
  386. handler: (selected) => {
  387. this.setValue(selected);
  388. if (!this.multiple) {
  389. this.close();
  390. }
  391. },
  392. };
  393. });
  394. return popoverOptions;
  395. }
  396. async openPopover(ev) {
  397. const { fill, labelPlacement } = this;
  398. const interfaceOptions = this.interfaceOptions;
  399. const mode = getIonMode(this);
  400. const showBackdrop = mode === 'md' ? false : true;
  401. const multiple = this.multiple;
  402. const value = this.value;
  403. let event = ev;
  404. let size = 'auto';
  405. const hasFloatingOrStackedLabel = labelPlacement === 'floating' || labelPlacement === 'stacked';
  406. /**
  407. * The popover should take up the full width
  408. * when using a fill in MD mode or if the
  409. * label is floating/stacked.
  410. */
  411. if (hasFloatingOrStackedLabel || (mode === 'md' && fill !== undefined)) {
  412. size = 'cover';
  413. /**
  414. * Otherwise the popover
  415. * should be positioned relative
  416. * to the native element.
  417. */
  418. }
  419. else {
  420. event = Object.assign(Object.assign({}, ev), { detail: {
  421. ionShadowTarget: this.nativeWrapperEl,
  422. } });
  423. }
  424. const popoverOpts = Object.assign(Object.assign({ mode,
  425. event, alignment: 'center', size,
  426. showBackdrop }, interfaceOptions), { component: 'ion-select-popover', cssClass: ['select-popover', interfaceOptions.cssClass], componentProps: {
  427. header: interfaceOptions.header,
  428. subHeader: interfaceOptions.subHeader,
  429. message: interfaceOptions.message,
  430. multiple,
  431. value,
  432. options: this.createOverlaySelectOptions(this.childOpts, value),
  433. } });
  434. return popoverController.create(popoverOpts);
  435. }
  436. async openActionSheet() {
  437. const mode = getIonMode(this);
  438. const interfaceOptions = this.interfaceOptions;
  439. const actionSheetOpts = Object.assign(Object.assign({ mode }, interfaceOptions), { buttons: this.createActionSheetButtons(this.childOpts, this.value), cssClass: ['select-action-sheet', interfaceOptions.cssClass] });
  440. return actionSheetController.create(actionSheetOpts);
  441. }
  442. async openAlert() {
  443. const interfaceOptions = this.interfaceOptions;
  444. const inputType = this.multiple ? 'checkbox' : 'radio';
  445. const mode = getIonMode(this);
  446. const alertOpts = Object.assign(Object.assign({ mode }, interfaceOptions), { header: interfaceOptions.header ? interfaceOptions.header : this.labelText, inputs: this.createAlertInputs(this.childOpts, inputType, this.value), buttons: [
  447. {
  448. text: this.cancelText,
  449. role: 'cancel',
  450. handler: () => {
  451. this.ionCancel.emit();
  452. },
  453. },
  454. {
  455. text: this.okText,
  456. handler: (selectedValues) => {
  457. this.setValue(selectedValues);
  458. },
  459. },
  460. ], cssClass: [
  461. 'select-alert',
  462. interfaceOptions.cssClass,
  463. this.multiple ? 'multiple-select-alert' : 'single-select-alert',
  464. ] });
  465. return alertController.create(alertOpts);
  466. }
  467. openModal() {
  468. const { multiple, value, interfaceOptions } = this;
  469. const mode = getIonMode(this);
  470. const modalOpts = Object.assign(Object.assign({}, interfaceOptions), { mode, cssClass: ['select-modal', interfaceOptions.cssClass], component: 'ion-select-modal', componentProps: {
  471. header: interfaceOptions.header,
  472. multiple,
  473. value,
  474. options: this.createOverlaySelectOptions(this.childOpts, value),
  475. } });
  476. return modalController.create(modalOpts);
  477. }
  478. /**
  479. * Close the select interface.
  480. */
  481. close() {
  482. if (!this.overlay) {
  483. return Promise.resolve(false);
  484. }
  485. return this.overlay.dismiss();
  486. }
  487. hasValue() {
  488. return this.getText() !== '';
  489. }
  490. get childOpts() {
  491. return Array.from(this.el.querySelectorAll('ion-select-option'));
  492. }
  493. /**
  494. * Returns any plaintext associated with
  495. * the label (either prop or slot).
  496. * Note: This will not return any custom
  497. * HTML. Use the `hasLabel` getter if you
  498. * want to know if any slotted label content
  499. * was passed.
  500. */
  501. get labelText() {
  502. const { label } = this;
  503. if (label !== undefined) {
  504. return label;
  505. }
  506. const { labelSlot } = this;
  507. if (labelSlot !== null) {
  508. return labelSlot.textContent;
  509. }
  510. return;
  511. }
  512. getText() {
  513. const selectedText = this.selectedText;
  514. if (selectedText != null && selectedText !== '') {
  515. return selectedText;
  516. }
  517. return generateText(this.childOpts, this.value, this.compareWith);
  518. }
  519. setFocus() {
  520. if (this.focusEl) {
  521. this.focusEl.focus();
  522. }
  523. }
  524. emitStyle() {
  525. const { disabled } = this;
  526. const style = {
  527. 'interactive-disabled': disabled,
  528. };
  529. this.ionStyle.emit(style);
  530. }
  531. renderLabel() {
  532. const { label } = this;
  533. return (h("div", { class: {
  534. 'label-text-wrapper': true,
  535. 'label-text-wrapper-hidden': !this.hasLabel,
  536. }, part: "label" }, label === undefined ? h("slot", { name: "label" }) : h("div", { class: "label-text" }, label)));
  537. }
  538. componentDidRender() {
  539. var _a;
  540. (_a = this.notchController) === null || _a === void 0 ? void 0 : _a.calculateNotchWidth();
  541. }
  542. /**
  543. * Gets any content passed into the `label` slot,
  544. * not the <slot> definition.
  545. */
  546. get labelSlot() {
  547. return this.el.querySelector('[slot="label"]');
  548. }
  549. /**
  550. * Returns `true` if label content is provided
  551. * either by a prop or a content. If you want
  552. * to get the plaintext value of the label use
  553. * the `labelText` getter instead.
  554. */
  555. get hasLabel() {
  556. return this.label !== undefined || this.labelSlot !== null;
  557. }
  558. /**
  559. * Renders the border container
  560. * when fill="outline".
  561. */
  562. renderLabelContainer() {
  563. const mode = getIonMode(this);
  564. const hasOutlineFill = mode === 'md' && this.fill === 'outline';
  565. if (hasOutlineFill) {
  566. /**
  567. * The outline fill has a special outline
  568. * that appears around the select and the label.
  569. * Certain stacked and floating label placements cause the
  570. * label to translate up and create a "cut out"
  571. * inside of that border by using the notch-spacer element.
  572. */
  573. return [
  574. h("div", { class: "select-outline-container" }, h("div", { class: "select-outline-start" }), h("div", { class: {
  575. 'select-outline-notch': true,
  576. 'select-outline-notch-hidden': !this.hasLabel,
  577. } }, h("div", { class: "notch-spacer", "aria-hidden": "true", ref: (el) => (this.notchSpacerEl = el) }, this.label)), h("div", { class: "select-outline-end" })),
  578. this.renderLabel(),
  579. ];
  580. }
  581. /**
  582. * If not using the outline style,
  583. * we can render just the label.
  584. */
  585. return this.renderLabel();
  586. }
  587. /**
  588. * Renders either the placeholder
  589. * or the selected values based on
  590. * the state of the select.
  591. */
  592. renderSelectText() {
  593. const { placeholder } = this;
  594. const displayValue = this.getText();
  595. let addPlaceholderClass = false;
  596. let selectText = displayValue;
  597. if (selectText === '' && placeholder !== undefined) {
  598. selectText = placeholder;
  599. addPlaceholderClass = true;
  600. }
  601. const selectTextClasses = {
  602. 'select-text': true,
  603. 'select-placeholder': addPlaceholderClass,
  604. };
  605. const textPart = addPlaceholderClass ? 'placeholder' : 'text';
  606. return (h("div", { "aria-hidden": "true", class: selectTextClasses, part: textPart }, selectText));
  607. }
  608. /**
  609. * Renders the chevron icon
  610. * next to the select text.
  611. */
  612. renderSelectIcon() {
  613. const mode = getIonMode(this);
  614. const { isExpanded, toggleIcon, expandedIcon } = this;
  615. let icon;
  616. if (isExpanded && expandedIcon !== undefined) {
  617. icon = expandedIcon;
  618. }
  619. else {
  620. const defaultIcon = mode === 'ios' ? chevronExpand : caretDownSharp;
  621. icon = toggleIcon !== null && toggleIcon !== void 0 ? toggleIcon : defaultIcon;
  622. }
  623. return h("ion-icon", { class: "select-icon", part: "icon", "aria-hidden": "true", icon: icon });
  624. }
  625. get ariaLabel() {
  626. var _a;
  627. const { placeholder, inheritedAttributes } = this;
  628. const displayValue = this.getText();
  629. // The aria label should be preferred over visible text if both are specified
  630. const definedLabel = (_a = inheritedAttributes['aria-label']) !== null && _a !== void 0 ? _a : this.labelText;
  631. /**
  632. * If developer has specified a placeholder
  633. * and there is nothing selected, the selectText
  634. * should have the placeholder value.
  635. */
  636. let renderedLabel = displayValue;
  637. if (renderedLabel === '' && placeholder !== undefined) {
  638. renderedLabel = placeholder;
  639. }
  640. /**
  641. * If there is a developer-defined label,
  642. * then we need to concatenate the developer label
  643. * string with the current current value.
  644. * The label for the control should be read
  645. * before the values of the control.
  646. */
  647. if (definedLabel !== undefined) {
  648. renderedLabel = renderedLabel === '' ? definedLabel : `${definedLabel}, ${renderedLabel}`;
  649. }
  650. return renderedLabel;
  651. }
  652. renderListbox() {
  653. const { disabled, inputId, isExpanded, required } = this;
  654. return (h("button", { disabled: disabled, id: inputId, "aria-label": this.ariaLabel, "aria-haspopup": "dialog", "aria-expanded": `${isExpanded}`, "aria-describedby": this.getHintTextID(), "aria-invalid": this.getHintTextID() === this.errorTextId, "aria-required": `${required}`, onFocus: this.onFocus, onBlur: this.onBlur, ref: (focusEl) => (this.focusEl = focusEl) }));
  655. }
  656. getHintTextID() {
  657. const { el, helperText, errorText, helperTextId, errorTextId } = this;
  658. if (el.classList.contains('ion-touched') && el.classList.contains('ion-invalid') && errorText) {
  659. return errorTextId;
  660. }
  661. if (helperText) {
  662. return helperTextId;
  663. }
  664. return undefined;
  665. }
  666. /**
  667. * Renders the helper text or error text values
  668. */
  669. renderHintText() {
  670. const { helperText, errorText, helperTextId, errorTextId } = this;
  671. return [
  672. h("div", { id: helperTextId, class: "helper-text", part: "supporting-text helper-text" }, helperText),
  673. h("div", { id: errorTextId, class: "error-text", part: "supporting-text error-text" }, errorText),
  674. ];
  675. }
  676. /**
  677. * Responsible for rendering helper text, and error text. This element
  678. * should only be rendered if hint text is set.
  679. */
  680. renderBottomContent() {
  681. const { helperText, errorText } = this;
  682. /**
  683. * undefined and empty string values should
  684. * be treated as not having helper/error text.
  685. */
  686. const hasHintText = !!helperText || !!errorText;
  687. if (!hasHintText) {
  688. return;
  689. }
  690. return h("div", { class: "select-bottom" }, this.renderHintText());
  691. }
  692. render() {
  693. const { disabled, el, isExpanded, expandedIcon, labelPlacement, justify, placeholder, fill, shape, name, value, hasFocus, } = this;
  694. const mode = getIonMode(this);
  695. const hasFloatingOrStackedLabel = labelPlacement === 'floating' || labelPlacement === 'stacked';
  696. const justifyEnabled = !hasFloatingOrStackedLabel && justify !== undefined;
  697. const rtl = isRTL(el) ? 'rtl' : 'ltr';
  698. const inItem = hostContext('ion-item', this.el);
  699. const shouldRenderHighlight = mode === 'md' && fill !== 'outline' && !inItem;
  700. const hasValue = this.hasValue();
  701. const hasStartEndSlots = el.querySelector('[slot="start"], [slot="end"]') !== null;
  702. renderHiddenInput(true, el, name, parseValue(value), disabled);
  703. /**
  704. * If the label is stacked, it should always sit above the select.
  705. * For floating labels, the label should move above the select if
  706. * the select has a value, is open, or has anything in either
  707. * the start or end slot.
  708. *
  709. * If there is content in the start slot, the label would overlap
  710. * it if not forced to float. This is also applied to the end slot
  711. * because with the default or solid fills, the select is not
  712. * vertically centered in the container, but the label is. This
  713. * causes the slots and label to appear vertically offset from each
  714. * other when the label isn't floating above the input. This doesn't
  715. * apply to the outline fill, but this was not accounted for to keep
  716. * things consistent.
  717. *
  718. * TODO(FW-5592): Remove hasStartEndSlots condition
  719. */
  720. const labelShouldFloat = labelPlacement === 'stacked' || (labelPlacement === 'floating' && (hasValue || isExpanded || hasStartEndSlots));
  721. return (h(Host, { key: '6dd3c92dc3c587960d767c7dd1c142fc20bef8ed', onClick: this.onClick, class: createColorClasses(this.color, {
  722. [mode]: true,
  723. 'in-item': inItem,
  724. 'in-item-color': hostContext('ion-item.ion-color', el),
  725. 'select-disabled': disabled,
  726. 'select-expanded': isExpanded,
  727. 'has-expanded-icon': expandedIcon !== undefined,
  728. 'has-value': hasValue,
  729. 'label-floating': labelShouldFloat,
  730. 'has-placeholder': placeholder !== undefined,
  731. 'has-focus': hasFocus,
  732. // TODO(FW-6451): Remove `ion-focusable` class in favor of `has-focus`.
  733. 'ion-focusable': true,
  734. [`select-${rtl}`]: true,
  735. [`select-fill-${fill}`]: fill !== undefined,
  736. [`select-justify-${justify}`]: justifyEnabled,
  737. [`select-shape-${shape}`]: shape !== undefined,
  738. [`select-label-placement-${labelPlacement}`]: true,
  739. }) }, h("label", { key: 'bc80ee471debb20b33d1cf55f55932b621f1744a', class: "select-wrapper", id: "select-label", onClick: this.onLabelClick }, this.renderLabelContainer(), h("div", { key: 'deea85c3a3769e90af0933c522028148ee5781a3', class: "select-wrapper-inner" }, h("slot", { key: 'af8192f4d8d5426b39a00ef2ed96f3c4a9e12908', name: "start" }), h("div", { key: '6c278fc6c56b18e26cae930d375aa1da05af135b', class: "native-wrapper", ref: (el) => (this.nativeWrapperEl = el), part: "container" }, this.renderSelectText(), this.renderListbox()), h("slot", { key: 'c459d54471029872b8b3e63f7dfb6bdb869b4942', name: "end" }), !hasFloatingOrStackedLabel && this.renderSelectIcon()), hasFloatingOrStackedLabel && this.renderSelectIcon(), shouldRenderHighlight && h("div", { key: '718960718fa91163dd4412e1865f476fef089127', class: "select-highlight" })), this.renderBottomContent()));
  740. }
  741. get el() { return this; }
  742. static get watchers() { return {
  743. "disabled": ["styleChanged"],
  744. "isExpanded": ["styleChanged"],
  745. "placeholder": ["styleChanged"],
  746. "value": ["styleChanged"]
  747. }; }
  748. static get style() { return {
  749. ios: IonSelectIosStyle0,
  750. md: IonSelectMdStyle0
  751. }; }
  752. }, [33, "ion-select", {
  753. "cancelText": [1, "cancel-text"],
  754. "color": [513],
  755. "compareWith": [1, "compare-with"],
  756. "disabled": [4],
  757. "fill": [1],
  758. "errorText": [1, "error-text"],
  759. "helperText": [1, "helper-text"],
  760. "interface": [1],
  761. "interfaceOptions": [8, "interface-options"],
  762. "justify": [1],
  763. "label": [1],
  764. "labelPlacement": [1, "label-placement"],
  765. "multiple": [4],
  766. "name": [1],
  767. "okText": [1, "ok-text"],
  768. "placeholder": [1],
  769. "selectedText": [1, "selected-text"],
  770. "toggleIcon": [1, "toggle-icon"],
  771. "expandedIcon": [1, "expanded-icon"],
  772. "shape": [1],
  773. "value": [1032],
  774. "required": [4],
  775. "isExpanded": [32],
  776. "hasFocus": [32],
  777. "open": [64]
  778. }, undefined, {
  779. "disabled": ["styleChanged"],
  780. "isExpanded": ["styleChanged"],
  781. "placeholder": ["styleChanged"],
  782. "value": ["styleChanged"]
  783. }]);
  784. const getOptionValue = (el) => {
  785. const value = el.value;
  786. return value === undefined ? el.textContent || '' : value;
  787. };
  788. const parseValue = (value) => {
  789. if (value == null) {
  790. return undefined;
  791. }
  792. if (Array.isArray(value)) {
  793. return value.join(',');
  794. }
  795. return value.toString();
  796. };
  797. const generateText = (opts, value, compareWith) => {
  798. if (value === undefined) {
  799. return '';
  800. }
  801. if (Array.isArray(value)) {
  802. return value
  803. .map((v) => textForValue(opts, v, compareWith))
  804. .filter((opt) => opt !== null)
  805. .join(', ');
  806. }
  807. else {
  808. return textForValue(opts, value, compareWith) || '';
  809. }
  810. };
  811. const textForValue = (opts, value, compareWith) => {
  812. const selectOpt = opts.find((opt) => {
  813. return compareOptions(value, getOptionValue(opt), compareWith);
  814. });
  815. return selectOpt ? selectOpt.textContent : null;
  816. };
  817. let selectIds = 0;
  818. const OPTION_CLASS = 'select-interface-option';
  819. function defineCustomElement$1() {
  820. if (typeof customElements === "undefined") {
  821. return;
  822. }
  823. const components = ["ion-select", "ion-action-sheet", "ion-alert", "ion-backdrop", "ion-button", "ion-buttons", "ion-checkbox", "ion-content", "ion-header", "ion-icon", "ion-item", "ion-label", "ion-list", "ion-list-header", "ion-modal", "ion-popover", "ion-radio", "ion-radio-group", "ion-ripple-effect", "ion-select-modal", "ion-select-popover", "ion-title", "ion-toolbar"];
  824. components.forEach(tagName => { switch (tagName) {
  825. case "ion-select":
  826. if (!customElements.get(tagName)) {
  827. customElements.define(tagName, Select);
  828. }
  829. break;
  830. case "ion-action-sheet":
  831. if (!customElements.get(tagName)) {
  832. defineCustomElement$n();
  833. }
  834. break;
  835. case "ion-alert":
  836. if (!customElements.get(tagName)) {
  837. defineCustomElement$m();
  838. }
  839. break;
  840. case "ion-backdrop":
  841. if (!customElements.get(tagName)) {
  842. defineCustomElement$l();
  843. }
  844. break;
  845. case "ion-button":
  846. if (!customElements.get(tagName)) {
  847. defineCustomElement$k();
  848. }
  849. break;
  850. case "ion-buttons":
  851. if (!customElements.get(tagName)) {
  852. defineCustomElement$j();
  853. }
  854. break;
  855. case "ion-checkbox":
  856. if (!customElements.get(tagName)) {
  857. defineCustomElement$i();
  858. }
  859. break;
  860. case "ion-content":
  861. if (!customElements.get(tagName)) {
  862. defineCustomElement$h();
  863. }
  864. break;
  865. case "ion-header":
  866. if (!customElements.get(tagName)) {
  867. defineCustomElement$g();
  868. }
  869. break;
  870. case "ion-icon":
  871. if (!customElements.get(tagName)) {
  872. defineCustomElement$f();
  873. }
  874. break;
  875. case "ion-item":
  876. if (!customElements.get(tagName)) {
  877. defineCustomElement$e();
  878. }
  879. break;
  880. case "ion-label":
  881. if (!customElements.get(tagName)) {
  882. defineCustomElement$d();
  883. }
  884. break;
  885. case "ion-list":
  886. if (!customElements.get(tagName)) {
  887. defineCustomElement$c();
  888. }
  889. break;
  890. case "ion-list-header":
  891. if (!customElements.get(tagName)) {
  892. defineCustomElement$b();
  893. }
  894. break;
  895. case "ion-modal":
  896. if (!customElements.get(tagName)) {
  897. defineCustomElement$a();
  898. }
  899. break;
  900. case "ion-popover":
  901. if (!customElements.get(tagName)) {
  902. defineCustomElement$9();
  903. }
  904. break;
  905. case "ion-radio":
  906. if (!customElements.get(tagName)) {
  907. defineCustomElement$8();
  908. }
  909. break;
  910. case "ion-radio-group":
  911. if (!customElements.get(tagName)) {
  912. defineCustomElement$7();
  913. }
  914. break;
  915. case "ion-ripple-effect":
  916. if (!customElements.get(tagName)) {
  917. defineCustomElement$6();
  918. }
  919. break;
  920. case "ion-select-modal":
  921. if (!customElements.get(tagName)) {
  922. defineCustomElement$5();
  923. }
  924. break;
  925. case "ion-select-popover":
  926. if (!customElements.get(tagName)) {
  927. defineCustomElement$4();
  928. }
  929. break;
  930. case "ion-title":
  931. if (!customElements.get(tagName)) {
  932. defineCustomElement$3();
  933. }
  934. break;
  935. case "ion-toolbar":
  936. if (!customElements.get(tagName)) {
  937. defineCustomElement$2();
  938. }
  939. break;
  940. } });
  941. }
  942. const IonSelect = Select;
  943. const defineCustomElement = defineCustomElement$1;
  944. export { IonSelect, defineCustomElement };