Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A11Y: Improvements to
<DToggleSwitch/>
component (#23514)
- Loading branch information
1 parent
c2cad3f
commit 4238c57
Showing
4 changed files
with
65 additions
and
40 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/assets/javascripts/discourse/app/components/d-toggle-switch.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Component from "@glimmer/component"; | ||
import I18n from "I18n"; | ||
import icon from "discourse-common/helpers/d-icon"; | ||
|
||
export default class DToggleSwitch extends Component { | ||
<template> | ||
<div class="d-toggle-switch"> | ||
<label class="d-toggle-switch--label"> | ||
{{! template-lint-disable no-redundant-role }} | ||
<button | ||
class="d-toggle-switch__checkbox" | ||
type="button" | ||
role="switch" | ||
aria-checked={{this.checked}} | ||
...attributes | ||
></button> | ||
{{! template-lint-enable no-redundant-role }} | ||
|
||
<span class="d-toggle-switch__checkbox-slider"> | ||
{{#if @state}} | ||
{{icon "check"}} | ||
{{/if}} | ||
</span> | ||
</label> | ||
|
||
<span class="d-toggle-switch__checkbox-label"> | ||
{{this.computedLabel}} | ||
</span> | ||
</div> | ||
</template> | ||
|
||
get computedLabel() { | ||
if (this.args.label) { | ||
return I18n.t(this.args.label); | ||
} | ||
return this.args.translatedLabel; | ||
} | ||
|
||
get checked() { | ||
return this.args.state ? "true" : "false"; | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
app/assets/javascripts/discourse/app/components/d-toggle-switch.hbs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
app/assets/javascripts/discourse/app/components/d-toggle-switch.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters