From 515ae35fc5c266531b9361fc568a13c4ff116ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Tue, 9 May 2023 11:43:08 +0300 Subject: [PATCH] Refactor #3922 - For SelectButton --- components/lib/selectbutton/SelectButton.d.ts | 17 +++++++++++++++++ components/lib/selectbutton/SelectButton.vue | 12 ++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/components/lib/selectbutton/SelectButton.d.ts b/components/lib/selectbutton/SelectButton.d.ts index d4801bde2..8c2b9f4d4 100755 --- a/components/lib/selectbutton/SelectButton.d.ts +++ b/components/lib/selectbutton/SelectButton.d.ts @@ -18,6 +18,7 @@ export declare type SelectButtonPassThroughOptionType = SelectButtonPassThroughA export interface SelectButtonPassThroughMethodOptions { props: SelectButtonProps; state: SelectButtonState; + context: SelectButtonContext; } /** @@ -71,6 +72,22 @@ export interface SelectButtonState { focusedIndex: number; } +/** + * Defines current options in SelectButton component. + */ +export interface SelectButtonContext { + /** + * Current active state of the item as a boolean. + * @defaultValue false + */ + active: boolean; + /** + * Current focused state of item as a boolean. + * @defaultValue false + */ + focused: boolean; +} + /** * Defines valid properties in SelectButton component. */ diff --git a/components/lib/selectbutton/SelectButton.vue b/components/lib/selectbutton/SelectButton.vue index 0d42ca6a2..0694b990e 100755 --- a/components/lib/selectbutton/SelectButton.vue +++ b/components/lib/selectbutton/SelectButton.vue @@ -14,10 +14,10 @@ @keydown="onKeydown($event, option, i)" @focus="onFocus($event)" @blur="onBlur($event, option)" - v-bind="ptm('button')" + v-bind="getPTOptions(option, 'button')" > - {{ getOptionLabel(option) }} + {{ getOptionLabel(option) }} @@ -78,6 +78,14 @@ export default { getOptionRenderKey(option) { return this.dataKey ? ObjectUtils.resolveFieldData(option, this.dataKey) : this.getOptionLabel(option); }, + getPTOptions(option, key) { + return this.ptm(key, { + context: { + active: this.isSelected(option), + disabled: this.isOptionDisabled(option) + } + }); + }, isOptionDisabled(option) { return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : false; },