5353 <span
5454 class =" vsf-button-field__btn-label"
5555 :class =" getLabelClass(option)"
56+ :style =" getLabelStyle(option)"
5657 v-html =" option.label"
5758 ></span >
5859 </template >
@@ -398,9 +399,6 @@ const itemGroupStyle = computed<CSSProperties>(() => {
398399});
399400
400401
401- const buttontextcolor = ref (' rgb(var(--v-theme-on-surface))' );
402-
403-
404402// -------------------------------------------------- Classes //
405403const itemGroupClass = computed (() => {
406404 return {
@@ -441,13 +439,38 @@ const buttonClassAdditional = (option: Option) => {
441439 };
442440};
443441
442+ const getLabelStyle = (option : Option ): CSSProperties => {
443+ const optionVariant = getVariant (option .value );
444+ const useBgColor = isActive (option .value ) || optionVariant === ' flat' || optionVariant === ' elevated' ;
445+
446+ // When the button shows a background color, let Vuetify's `bg-<color>`
447+ // contrast color drive the label text so a selected button gets the correct
448+ // on-color (e.g. black on a light color). Only the neutral, un-selected
449+ // state forces `on-surface` for readability.
450+ if (useBgColor ) {
451+ return {};
452+ }
453+
454+ return {
455+ color: ' rgb(var(--v-theme-on-surface))' ,
456+ };
457+ };
458+
444459const getLabelClass = (option : Option ): object => {
445460 const isActiveOption = isActive (option .value );
446461 const optionVariant = getVariant (option .value );
447462 const useBgColor = isActiveOption || optionVariant === ' flat' || optionVariant === ' elevated' ;
463+ const bgColor = option ?.color ?? field .value ?.color ;
448464
449465 return {
450- [` bg-${option ?.color } ` ]: useBgColor ,
466+ // The field/option `class` is applied to the label itself. A
467+ // text-transform utility set directly on the label wins over the value
468+ // it would otherwise inherit from the button (e.g. a global `VBtn`
469+ // `text-uppercase` default), so the app default is respected when no
470+ // class is set but can be altered per-field/option when one is.
471+ [` bg-${bgColor } ` ]: useBgColor && bgColor != null ,
472+ [` ${field .value ?.class } ` ]: field .value ?.class != null ,
473+ [` ${option ?.class } ` ]: option ?.class != null ,
451474 };
452475};
453476
@@ -470,10 +493,4 @@ function containsSizeUnit(value: string | number): boolean {
470493.v-item-group {
471494 flex-wrap : wrap ;
472495}
473-
474- .vsf-button-field {
475- & __btn-label {
476- color : v-bind (buttontextcolor );
477- }
478- }
479496 </style >
0 commit comments