mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:03:22 +08:00
A11Y: add screenreader markup for category color pickers (#29351)
This commit is contained in:
parent
5af6edba6f
commit
5aa32b4621
|
@ -3,10 +3,12 @@
|
|||
@maxlength={{this.maxlength}}
|
||||
@input={{this.onHexInput}}
|
||||
class="hex-input"
|
||||
aria-labelledby={{this.ariaLabelledby}}
|
||||
/>
|
||||
<input
|
||||
class="picker"
|
||||
type="color"
|
||||
value={{this.normalizedHexValue}}
|
||||
{{on "input" this.onPickerInput}}
|
||||
aria-labelledby={{this.ariaLabelledby}}
|
||||
/>
|
|
@ -9,7 +9,7 @@ import discourseComputed from "discourse-common/utils/decorators";
|
|||
import I18n from "discourse-i18n";
|
||||
|
||||
@tagName("button")
|
||||
@attributeBindings("style", "title")
|
||||
@attributeBindings("style", "title", "ariaLabel:aria-label")
|
||||
@classNameBindings(":colorpicker", "isUsed:used-color:unused-color")
|
||||
export default class ColorPickerChoice extends Component {
|
||||
@discourseComputed("color", "usedColors")
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@color={{c}}
|
||||
@usedColors={{this.usedColors}}
|
||||
@selectColor={{action "selectColor"}}
|
||||
@ariaLabel={{this.getColorLabel c}}
|
||||
>
|
||||
{{d-icon "check"}}
|
||||
</ColorPickerChoice>
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
import Component from "@ember/component";
|
||||
import { action } from "@ember/object";
|
||||
import { classNames } from "@ember-decorators/component";
|
||||
import { attributeBindings, classNames } from "@ember-decorators/component";
|
||||
import I18n from "discourse-i18n";
|
||||
|
||||
@classNames("colors-container")
|
||||
@attributeBindings("role", "ariaLabel:aria-label")
|
||||
export default class ColorPicker extends Component {
|
||||
role = "group";
|
||||
|
||||
@action
|
||||
selectColor(color) {
|
||||
this.set("value", color);
|
||||
}
|
||||
|
||||
@action
|
||||
getColorLabel(color) {
|
||||
const isUsed = this.usedColors?.includes(color.toUpperCase())
|
||||
? I18n.t("category.color_used")
|
||||
: "";
|
||||
return `#${color} ${isUsed}`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,28 +67,38 @@
|
|||
{{html-safe this.categoryBadgePreview}}
|
||||
|
||||
<section class="field">
|
||||
<span class="color-title">{{i18n "category.background_color"}}:</span>
|
||||
<span id="background-color-label" class="color-title">{{i18n
|
||||
"category.background_color"
|
||||
}}:</span>
|
||||
<div class="colorpicker-wrapper">
|
||||
<ColorInput
|
||||
@hexValue={{this.category.color}}
|
||||
@valid={{this.category.colorValid}}
|
||||
@ariaLabelledby="background-color-label"
|
||||
/>
|
||||
<ColorPicker
|
||||
@colors={{this.backgroundColors}}
|
||||
@usedColors={{this.usedBackgroundColors}}
|
||||
@value={{this.category.color}}
|
||||
@ariaLabel={{i18n "category.predefined_colors"}}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="field">
|
||||
<span class="color-title">{{i18n "category.foreground_color"}}:</span>
|
||||
<span id="foreground-color-label" class="color-title">{{i18n
|
||||
"category.foreground_color"
|
||||
}}:</span>
|
||||
<div class="colorpicker-wrapper edit-text-color">
|
||||
<ColorInput @hexValue={{this.category.text_color}} />
|
||||
<ColorInput
|
||||
@hexValue={{this.category.text_color}}
|
||||
@ariaLabelledby="foreground-color-label"
|
||||
/>
|
||||
<ColorPicker
|
||||
@colors={{this.foregroundColors}}
|
||||
@value={{this.category.text_color}}
|
||||
@id="edit-text-color"
|
||||
@ariaLabel={{i18n "category.predefined_colors"}}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -4044,6 +4044,8 @@ en:
|
|||
badge_colors: "Badge colors"
|
||||
background_color: "Background color"
|
||||
foreground_color: "Foreground color"
|
||||
color_used: "Color in use"
|
||||
predefined_colors: "Predefined color options"
|
||||
name_placeholder: "One or two words maximum"
|
||||
color_placeholder: "Any web color"
|
||||
delete_confirm: "Are you sure you want to delete this category?"
|
||||
|
|
Loading…
Reference in New Issue
Block a user