mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 00:27:41 +08:00
fix(range, select): prefer labels passed by developer (#29145)
This commit is contained in:
@ -2,7 +2,7 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core';
|
||||
import { Component, Element, Event, Host, Prop, State, Watch, h } from '@stencil/core';
|
||||
import { findClosestIonContent, disableContentScrollY, resetContentScrollY } from '@utils/content';
|
||||
import type { Attributes } from '@utils/helpers';
|
||||
import { inheritAriaAttributes, clamp, debounceEvent, getAriaLabel, renderHiddenInput } from '@utils/helpers';
|
||||
import { inheritAriaAttributes, clamp, debounceEvent, renderHiddenInput } from '@utils/helpers';
|
||||
import { printIonWarning } from '@utils/logging';
|
||||
import { isRTL } from '@utils/rtl';
|
||||
import { createColorClasses, hostContext } from '@utils/theme';
|
||||
@ -624,28 +624,16 @@ export class Range implements ComponentInterface {
|
||||
min,
|
||||
max,
|
||||
step,
|
||||
el,
|
||||
handleKeyboard,
|
||||
pressedKnob,
|
||||
disabled,
|
||||
pin,
|
||||
ratioLower,
|
||||
ratioUpper,
|
||||
inheritedAttributes,
|
||||
rangeId,
|
||||
pinFormatter,
|
||||
inheritedAttributes,
|
||||
} = this;
|
||||
|
||||
/**
|
||||
* Look for external label, ion-label, or aria-labelledby.
|
||||
* If none, see if user placed an aria-label on the host
|
||||
* and use that instead.
|
||||
*/
|
||||
let { labelText } = getAriaLabel(el, rangeId!);
|
||||
if (labelText === undefined || labelText === null) {
|
||||
labelText = inheritedAttributes['aria-label'];
|
||||
}
|
||||
|
||||
let barStart = `${ratioLower * 100}%`;
|
||||
let barEnd = `${100 - ratioUpper * 100}%`;
|
||||
|
||||
@ -715,11 +703,6 @@ export class Range implements ComponentInterface {
|
||||
}
|
||||
}
|
||||
|
||||
let labelledBy: string | undefined;
|
||||
if (this.hasLabel) {
|
||||
labelledBy = 'range-label';
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
class="range-slider"
|
||||
@ -791,8 +774,7 @@ export class Range implements ComponentInterface {
|
||||
handleKeyboard,
|
||||
min,
|
||||
max,
|
||||
labelText,
|
||||
labelledBy,
|
||||
inheritedAttributes,
|
||||
})}
|
||||
|
||||
{this.dualKnobs &&
|
||||
@ -807,8 +789,7 @@ export class Range implements ComponentInterface {
|
||||
handleKeyboard,
|
||||
min,
|
||||
max,
|
||||
labelText,
|
||||
labelledBy,
|
||||
inheritedAttributes,
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
@ -887,27 +868,13 @@ interface RangeKnob {
|
||||
pressed: boolean;
|
||||
pin: boolean;
|
||||
pinFormatter: PinFormatter;
|
||||
labelText?: string | null;
|
||||
labelledBy?: string;
|
||||
inheritedAttributes: Attributes;
|
||||
handleKeyboard: (name: KnobName, isIncrease: boolean) => void;
|
||||
}
|
||||
|
||||
const renderKnob = (
|
||||
rtl: boolean,
|
||||
{
|
||||
knob,
|
||||
value,
|
||||
ratio,
|
||||
min,
|
||||
max,
|
||||
disabled,
|
||||
pressed,
|
||||
pin,
|
||||
handleKeyboard,
|
||||
labelText,
|
||||
labelledBy,
|
||||
pinFormatter,
|
||||
}: RangeKnob
|
||||
{ knob, value, ratio, min, max, disabled, pressed, pin, handleKeyboard, pinFormatter, inheritedAttributes }: RangeKnob
|
||||
) => {
|
||||
const start = rtl ? 'right' : 'left';
|
||||
|
||||
@ -919,6 +886,9 @@ const renderKnob = (
|
||||
return style;
|
||||
};
|
||||
|
||||
// The aria label should be preferred over visible text if both are specified
|
||||
const ariaLabel = inheritedAttributes['aria-label'];
|
||||
|
||||
return (
|
||||
<div
|
||||
onKeyDown={(ev: KeyboardEvent) => {
|
||||
@ -946,8 +916,8 @@ const renderKnob = (
|
||||
style={knobStyle()}
|
||||
role="slider"
|
||||
tabindex={disabled ? -1 : 0}
|
||||
aria-label={labelledBy === undefined ? labelText : null}
|
||||
aria-labelledby={labelledBy !== undefined ? labelledBy : null}
|
||||
aria-label={ariaLabel !== undefined ? ariaLabel : null}
|
||||
aria-labelledby={ariaLabel === undefined ? 'range-label' : null}
|
||||
aria-valuemin={min}
|
||||
aria-valuemax={max}
|
||||
aria-disabled={disabled ? 'true' : null}
|
||||
|
||||
Reference in New Issue
Block a user