Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reactive translations #1761

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-bears-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solid-design-system/components': patch
---

Make sd-select and sd-combobox placeholders translatable.
16 changes: 16 additions & 0 deletions packages/components/src/components/combobox/combobox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,4 +1283,20 @@ describe.skip('<sd-combobox>', () => {

expect(el.value).to.equal('Option 2');
});

it('should display translated placeholder if lang attribute is set', async () => {
const el = await fixture<SdSelect>(html`
<sd-combobox lang="de">
<sd-option value="option-1">Option 1</sd-option>
<sd-option value="option-2">Option 2</sd-option>
<sd-option value="option-3">Option 3</sd-option>
</sd-combobox>
`);

const placeholder = el.shadowRoot!.querySelector('[part~="display-input"]')!;

await el.updateComplete;

expect(placeholder.getAttribute('placeholder')).to.equal('Bitte suchen und auswählen');
});
});
6 changes: 4 additions & 2 deletions packages/components/src/components/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default class SdCombobox extends SolidElement implements SolidFormControl
@property({ reflect: true }) size: 'lg' | 'md' | 'sm' = 'lg';

/** Placeholder text to show as a hint when the combobox is empty. */
@property() placeholder = this.localize.term('comboboxDefaultPlaceholder');
@property() placeholder = '';

/** Disables the combobox control. */
@property({ reflect: true, type: Boolean }) disabled = false;
Expand Down Expand Up @@ -1241,7 +1241,9 @@ export default class SdCombobox extends SolidElement implements SolidFormControl
this.selectedTextLabel && !this.multiple ? 'placeholder-black' : 'placeholder-neutral-700'
)}
type="text"
placeholder=${this.selectedTextLabel && !this.multiple ? this.selectedTextLabel : this.placeholder}
placeholder=${this.selectedTextLabel && !this.multiple
? this.selectedTextLabel
: this.placeholder || this.localize.term('comboboxDefaultPlaceholder')}
.disabled=${this.disabled}
.value=${this.displayInputValue}
autocomplete="off"
Expand Down
18 changes: 18 additions & 0 deletions packages/components/src/components/select/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,22 @@ describe('<sd-select>', () => {
expect(hideHandler).to.have.been.calledOnce;
expect(afterHideHandler).to.have.been.calledOnce;
});

it('should display translated placeholder and clear entry texts if lang attribute is set', async () => {
const el = await fixture<SdSelect>(html`
<sd-select lang="de" value="option-1" clearable>
<sd-option value="option-1">Option 1</sd-option>
<sd-option value="option-2">Option 2</sd-option>
<sd-option value="option-3">Option 3</sd-option>
</sd-select>
`);

const clearButton: HTMLButtonElement = el.shadowRoot!.querySelector('[part~="clear-button"]')!;
const placeholder = el.shadowRoot!.querySelector('[part~="display-input"]')!;

await el.updateComplete;

expect(placeholder.getAttribute('placeholder')).to.equal('Bitte auswählen');
expect(clearButton.getAttribute('aria-label')).to.equal('Eingabe löschen');
});
});
4 changes: 2 additions & 2 deletions packages/components/src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
@property() label = '';

/** Placeholder text to show as a hint when the select is empty. */
@property() placeholder = this.localize.term('selectDefaultPlaceholder');
@property() placeholder = '';

/** Disables the select control. */
@property({ type: Boolean, reflect: true }) disabled = false;
Expand Down Expand Up @@ -990,8 +990,8 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
this.multiple && this.useTags && this.value.length > 0 ? 'hidden' : ''
)}
type="text"
placeholder=${this.placeholder}
.disabled=${this.disabled}
placeholder=${this.placeholder || this.localize.term('selectDefaultPlaceholder')}
.value=${this.displayLabel}
autocomplete="off"
spellcheck="false"
Expand Down
Loading