Skip to content

Commit

Permalink
refactor: deprecate inputId on form components (#319)
Browse files Browse the repository at this point in the history
The inputId property on form components will be replaced by an internal getter based on the id property. Where applicable, the form components will forward focus events (e.g. from a label) to the internal input element.
  • Loading branch information
kyubisation authored Feb 27, 2020
1 parent cedf4ab commit 2d2f5e1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
6 changes: 4 additions & 2 deletions projects/sbb-esta/angular-core/base/src/checkbox-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export class SbbCheckboxChange<TCheckbox extends CheckboxBase = CheckboxBase> {
export abstract class CheckboxBase implements ControlValueAccessor {
/** A unique id for the checkbox input. If none is supplied, it will be auto-generated. */
@Input() @HostBinding() id: string;
/** Identifier of a checkbox field */
// TODO: Refactor to a getter for Angular 9
/**
* Identifier of a checkbox field
* @deprecated This will be replaced by an internal getter, based on the id property.
*/
@Input() inputId: string;
/** Value contained in a checkbox field */
@Input() value: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export abstract class FormFieldControl<TValue> {
readonly stateChanges: Observable<void>;
/** The id of the form field. */
readonly id: string;
/** The id of the inner input field. Can be the same as the id property. */
/**
* The id of the inner input field. Can be the same as the id property.
* @deprecated This will be replaced by an internal getter, based on the id property.
*/
readonly inputId: string;
/** The attached NgControl, if any exists. */
readonly ngControl: NgControl | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export abstract class RadioButton extends _RadioButtonMixinBase
/** The id of this component. */
// tslint:disable-next-line: no-input-rename
@Input() @HostBinding('attr.id') id: string = this._uniqueId;
/** Radio input identifier. */
/**
* Radio input identifier.
* @deprecated This will be replaced by an internal getter, based on the id property.
*/
@Input() inputId = `${this.id}-input`;
/** Analog to HTML 'name' attribute used to group radios for unique selection. */
@Input() name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class FileSelectorComponent implements ControlValueAccessor, FileSelector

/**
* Identifier of a sbb-file-selector component.
* @deprecated This will be replaced by an internal getter, based on the id property.
*/
@Input() inputId = `sbb-file-selector-${counter++}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export class InputDirective extends SbbNativeInputBase
@Input()
id = `sbb-native-input-${nextId++}`;

/**
* @deprecated This will be replaced by an internal getter, based on the id property.
*/
get inputId() {
return this.id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export class SelectComponent extends SbbSelectMixinBase

/**
* Implemented as part of FormFieldControl.
* @deprecated This will be replaced by an internal getter, based on the id property.
* @docs-private
*/
get inputId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export class TextareaComponent implements ControlValueAccessor {
private _required = false;
/** Placeholder value for the textarea. */
@Input() placeholder = '';
/** Identifier of textarea. */
/**
* Identifier of textarea.
* @deprecated This will be replaced by an internal getter, based on the id property.
*/
@Input() inputId = `sbb-textarea-input-id-${++nextId}`;
/** @docs-private */
@ViewChild('textarea', { static: true }) _textarea: ElementRef<HTMLTextAreaElement>;
Expand Down

0 comments on commit 2d2f5e1

Please sign in to comment.