Skip to content

Commit

Permalink
fix(sbb-form-field): ensure input element is detected during hydration (
Browse files Browse the repository at this point in the history
#2894)

Closes #2877
  • Loading branch information
kyubisation authored Jul 5, 2024
1 parent c5bbb96 commit 9519827
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/elements/form-field/form-field-clear/form-field-clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { customElement } from 'lit/decorators.js';
import { SbbButtonBaseElement } from '../../core/base-elements.js';
import { SbbConnectedAbortController, SbbLanguageController } from '../../core/controllers.js';
import { hostAttributes } from '../../core/decorators.js';
import { hostContext } from '../../core/dom.js';
import { i18nClearInput } from '../../core/i18n.js';
import { SbbNegativeMixin } from '../../core/mixins.js';
import type { SbbFormFieldElement } from '../form-field.js';
Expand All @@ -24,17 +23,15 @@ import '../../icon.js';
export class SbbFormFieldClearElement extends SbbNegativeMixin(SbbButtonBaseElement) {
public static override styles: CSSResultGroup = style;

private _formField?: SbbFormFieldElement;
private _formField?: SbbFormFieldElement | null;
private _abort = new SbbConnectedAbortController(this);
private _language = new SbbLanguageController(this);

public override connectedCallback(): void {
super.connectedCallback();
const signal = this._abort.signal;
this.addEventListener('click', () => this._handleClick(), { signal });
this._formField =
(hostContext('sbb-form-field', this) as SbbFormFieldElement) ??
(hostContext('[data-form-field]', this) as SbbFormFieldElement);
this._formField = this.closest<SbbFormFieldElement>('sbb-form-field, [data-form-field]');

if (this._formField) {
this.negative = this._formField.hasAttribute('negative');
Expand Down
4 changes: 2 additions & 2 deletions src/elements/form-field/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SbbConnectedAbortController, SbbLanguageController } from '../../core/c
import { slotState } from '../../core/decorators.js';
import { isFirefox, setOrRemoveAttribute } from '../../core/dom.js';
import { i18nOptional } from '../../core/i18n.js';
import { SbbNegativeMixin } from '../../core/mixins.js';
import { SbbHydrationMixin, SbbNegativeMixin } from '../../core/mixins.js';
import { AgnosticMutationObserver } from '../../core/observers.js';
import type { SbbSelectElement } from '../../select.js';

Expand All @@ -32,7 +32,7 @@ const supportedPopupTagNames = ['sbb-autocomplete', 'sbb-select'];
*/
@customElement('sbb-form-field')
@slotState()
export class SbbFormFieldElement extends SbbNegativeMixin(LitElement) {
export class SbbFormFieldElement extends SbbNegativeMixin(SbbHydrationMixin(LitElement)) {
public static override styles: CSSResultGroup = style;

private readonly _supportedNativeInputElements = ['input', 'select', 'textarea'];
Expand Down

0 comments on commit 9519827

Please sign in to comment.