()
| 316 | |
| 317 | @Watch('inputs') |
| 318 | inputsChanged() { |
| 319 | const inputs = this.inputs; |
| 320 | |
| 321 | // Get the first input that is not disabled and the checked one |
| 322 | // If an enabled checked input exists, set it to be the focusable input |
| 323 | // otherwise we default to focus the first input |
| 324 | // This will only be used when the input is type radio |
| 325 | const first = inputs.find((input) => !input.disabled); |
| 326 | const checked = inputs.find((input) => input.checked && !input.disabled); |
| 327 | const focusable = checked || first; |
| 328 | |
| 329 | // An alert can be created with several different inputs. Radios, |
| 330 | // checkboxes and inputs are all accepted, but they cannot be mixed. |
| 331 | const inputTypes = new Set(inputs.map((i) => i.type)); |
| 332 | if (inputTypes.has('checkbox') && inputTypes.has('radio')) { |
| 333 | printIonWarning( |
| 334 | `[ion-alert] - Alert cannot mix input types: ${Array.from(inputTypes.values()).join( |
| 335 | '/' |
| 336 | )}. Please see alert docs for more info.` |
| 337 | ); |
| 338 | } |
| 339 | |
| 340 | this.inputType = inputTypes.values().next().value; |
| 341 | this.processedInputs = inputs.map( |
| 342 | (i, index) => |
| 343 | ({ |
| 344 | type: i.type || 'text', |
| 345 | name: i.name || `${index}`, |
| 346 | placeholder: i.placeholder || '', |
| 347 | value: i.value, |
| 348 | label: i.label, |
| 349 | checked: !!i.checked, |
| 350 | disabled: !!i.disabled, |
| 351 | id: i.id || `alert-input-${this.overlayIndex}-${index}`, |
| 352 | handler: i.handler, |
| 353 | min: i.min, |
| 354 | max: i.max, |
| 355 | cssClass: i.cssClass ?? '', |
| 356 | attributes: i.attributes || {}, |
| 357 | tabindex: i.type === 'radio' && i !== focusable ? -1 : 0, |
| 358 | } as AlertInput) |
| 359 | ); |
| 360 | } |
| 361 | |
| 362 | connectedCallback() { |
| 363 | prepareOverlay(this.el); |
no test coverage detected