mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 11:17:19 +08:00

Issue number: internal --------- ## What is the current behavior? In Ionic Framework v7, we [simplified the select syntax](https://ionic.io/blog/ionic-7-is-here#simplified-form-control-syntax) so that it was no longer required to be placed inside of an `ion-item`. We maintained backwards compatibility by adding a `legacy` property which allowed it to continue to be styled properly when written in the following way: ```html <ion-item> <ion-label>Label</ion-label> <ion-select></ion-select> </ion-item> ``` While this was supported in v7, console warnings were logged to notify developers that they needed to update this syntax for the best accessibility experience. ## What is the new behavior? - Removes the `legacy` property and support for the legacy syntax. Developers should follow the [migration guide](https://ionicframework.com/docs/api/select#migrating-from-legacy-select-syntax) in the select documentation to update their apps. The new syntax requires a `label` or `aria-label` on `ion-select`: ```html <ion-item> <ion-select label="Label"></ion-select> </ion-item> ``` - Removes the legacy tests under under `select/test/legacy/` and all related screenshots - Removes the select usage from `item/test/disabled`, `item/test/legacy/alignment`, and `item/test/legacy/disabled` and all related screenshots if the test was removed ## Does this introduce a breaking change? - [x] Yes - [ ] No 1. Developers have had console warnings when using the legacy syntax since the v7 release. The migration guide for the new select syntax is outlined in the [Select documentation](https://ionicframework.com/docs/api/select#migrating-from-legacy-select-syntax). 2. This change has been documented in the Breaking Changes document with a link to the migration guide. BREAKING CHANGE: The `legacy` property and support for the legacy syntax, which involved placing an `ion-select` inside of an `ion-item` with an `ion-label`, have been removed from select. For more information on migrating from the legacy select syntax, refer to the [Select documentation](https://ionicframework.com/docs/api/select#migrating-from-legacy-select-syntax). --------- Co-authored-by: ionitron <hi@ionicframework.com>
107 lines
2.7 KiB
TypeScript
107 lines
2.7 KiB
TypeScript
import {
|
|
ChangeDetectionStrategy,
|
|
ChangeDetectorRef,
|
|
Component,
|
|
ElementRef,
|
|
EventEmitter,
|
|
HostListener,
|
|
Injector,
|
|
NgZone,
|
|
forwardRef,
|
|
} from '@angular/core';
|
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
import { ValueAccessor } from '@ionic/angular/common';
|
|
import type { SelectChangeEventDetail, Components } from '@ionic/core/components';
|
|
import { defineCustomElement } from '@ionic/core/components/ion-select.js';
|
|
|
|
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';
|
|
|
|
const SELECT_INPUTS = [
|
|
'cancelText',
|
|
'color',
|
|
'compareWith',
|
|
'disabled',
|
|
'expandedIcon',
|
|
'fill',
|
|
'interface',
|
|
'interfaceOptions',
|
|
'justify',
|
|
'label',
|
|
'labelPlacement',
|
|
'mode',
|
|
'multiple',
|
|
'name',
|
|
'okText',
|
|
'placeholder',
|
|
'selectedText',
|
|
'shape',
|
|
'toggleIcon',
|
|
'value',
|
|
];
|
|
|
|
/**
|
|
* Pulling the provider into an object and using PURE works
|
|
* around an ng-packagr issue that causes
|
|
* components with multiple decorators and
|
|
* a provider to be re-assigned. This re-assignment
|
|
* is not supported by Webpack and causes treeshaking
|
|
* to not work on these kinds of components.
|
|
*/
|
|
const accessorProvider = {
|
|
provide: NG_VALUE_ACCESSOR,
|
|
useExisting: /*@__PURE__*/ forwardRef(() => IonSelect),
|
|
multi: true,
|
|
};
|
|
|
|
@ProxyCmp({
|
|
defineCustomElementFn: defineCustomElement,
|
|
inputs: SELECT_INPUTS,
|
|
methods: ['open'],
|
|
})
|
|
@Component({
|
|
selector: 'ion-select',
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
template: '<ng-content></ng-content>',
|
|
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
|
|
inputs: SELECT_INPUTS,
|
|
providers: [accessorProvider],
|
|
standalone: true,
|
|
})
|
|
export class IonSelect extends ValueAccessor {
|
|
protected el: HTMLElement;
|
|
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone, injector: Injector) {
|
|
super(injector, r);
|
|
c.detach();
|
|
this.el = r.nativeElement;
|
|
proxyOutputs(this, this.el, ['ionChange', 'ionCancel', 'ionDismiss', 'ionFocus', 'ionBlur']);
|
|
}
|
|
|
|
@HostListener('ionChange', ['$event.target'])
|
|
handleIonChange(el: HTMLIonSelectElement): void {
|
|
this.handleValueChange(el, el.value);
|
|
}
|
|
}
|
|
|
|
export declare interface IonSelect extends Components.IonSelect {
|
|
/**
|
|
* Emitted when the value has changed.
|
|
*/
|
|
ionChange: EventEmitter<CustomEvent<SelectChangeEventDetail>>;
|
|
/**
|
|
* Emitted when the selection is cancelled.
|
|
*/
|
|
ionCancel: EventEmitter<CustomEvent<void>>;
|
|
/**
|
|
* Emitted when the overlay is dismissed.
|
|
*/
|
|
ionDismiss: EventEmitter<CustomEvent<void>>;
|
|
/**
|
|
* Emitted when the select has focus.
|
|
*/
|
|
ionFocus: EventEmitter<CustomEvent<void>>;
|
|
/**
|
|
* Emitted when the select loses focus.
|
|
*/
|
|
ionBlur: EventEmitter<CustomEvent<void>>;
|
|
}
|