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(elements|ino-select): update on ino-option change #520

Merged
merged 3 commits into from
Feb 16, 2022
Merged
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
15 changes: 12 additions & 3 deletions packages/elements/src/components/ino-select/ino-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Element,
Event,
EventEmitter,
forceUpdate,
h,
Host,
Listen,
Expand All @@ -27,7 +28,9 @@ export class Select implements ComponentInterface {
// An internal instance of the material design form field.
private mdcSelectInstance?: MDCSelect;
private mdcSelectContainerEl?: HTMLDivElement;
private mdcOptionsListEl?: HTMLUListElement;
private nativeInputElement?: HTMLInputElement;
private optionsObserver: MutationObserver;

@Element() el!: HTMLElement;

Expand Down Expand Up @@ -104,19 +107,25 @@ export class Select implements ComponentInterface {
connectedCallback() {
// in case of usage e.g. in a popover this is necessary
this.create();
this.optionsObserver = new MutationObserver(() => {
forceUpdate(this.el);
});
}

componentDidLoad() {
this.create();
this.optionsObserver.observe(this.mdcOptionsListEl, { childList: true });
}

componentDidUpdate() {
// This adjusts the dimensions, whenever a property changes, e.g. the label gets translated to another language
this.mdcSelectInstance?.layoutOptions();
this.mdcSelectInstance?.layout();
}

disconnectedCallback() {
this.mdcSelectInstance?.destroy();
this.optionsObserver?.disconnect();
}

private create = () => {
Expand Down Expand Up @@ -189,7 +198,7 @@ export class Select implements ComponentInterface {
<input
class="ino-hidden-input"
aria-hidden
ref={el => (this.nativeInputElement = el)}
ref={(el) => (this.nativeInputElement = el)}
required={this.required}
disabled={this.disabled}
></input>
Expand All @@ -199,7 +208,7 @@ export class Select implements ComponentInterface {

return (
<Host name={this.name}>
<div class={classSelect} ref={el => (this.mdcSelectContainerEl = el)}>
<div class={classSelect} ref={(el) => (this.mdcSelectContainerEl = el)}>
{hiddenInput}
<div class="mdc-select__anchor" aria-required={this.required}>
{leadingSlotHasContent && (
Expand All @@ -218,7 +227,7 @@ export class Select implements ComponentInterface {
/>
</div>
<div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
<ul class="mdc-list">
<ul class="mdc-list" ref={(el) => (this.mdcOptionsListEl = el)}>
<slot />
</ul>
</div>
Expand Down