refactor: clicking option sets value

This commit is contained in:
Liam DeBeasi
2023-12-01 14:58:01 -05:00
parent b68c93d55d
commit 2f3f9dc9ca

View File

@@ -64,6 +64,19 @@ export class PickerColumnOption implements ComponentInterface {
this.ariaLabel = inheritedAttributes['aria-label'] || null;
}
/**
* When an option is clicked update the
* parent picker column value. This
* component will handle centering the option
* in the column view.
*/
onClick() {
const parentPickerColumn = this.el.closest('ion-picker-column');
if (parentPickerColumn !== null) {
parentPickerColumn.setValue(this.value);
}
}
render() {
const { color, value, disabled, ariaLabel } = this;
const mode = getIonMode(this);
@@ -75,7 +88,12 @@ export class PickerColumnOption implements ComponentInterface {
['option-disabled']: disabled,
})}
>
<button tabindex="-1" aria-label={ariaLabel} disabled={disabled}>
<button
tabindex="-1"
aria-label={ariaLabel}
disabled={disabled}
onClick={() => this.onClick()}
>
<slot>{value}</slot>
</button>
</Host>