Skip to content

Commit

Permalink
Merge pull request #2221 from Sefaria/rtl-accessibility
Browse files Browse the repository at this point in the history
Rtl accessibility
  • Loading branch information
akiva10b authored Jan 7, 2025
2 parents e84f7cd + a0727a0 commit ca4f055
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
4 changes: 4 additions & 0 deletions static/css/s2.css
Original file line number Diff line number Diff line change
Expand Up @@ -13552,6 +13552,10 @@ span.ref-link-color-3 {color: blue}
justify-content: center;
}

.show-source-translation-buttons input {
display: none;
}

.show-source-translation-buttons .button {
margin: unset;
display: flex;
Expand Down
16 changes: 12 additions & 4 deletions static/js/FontSizeButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ function FontSizeButtons() {
const {setOption} = useContext(ReaderPanelContext);
return (
<div className="font-size-line">
<button onClick={()=>setOption('fontSize', 'smaller')} className="font-size-button preventClosing">
<img src="/static/icons/reduce_font.svg" alt="Reduce font size" />
<button
onClick={()=>setOption('fontSize', 'smaller')}
className="font-size-button preventClosing"
aria-label="Decrease font size"
>
<img src="/static/icons/reduce_font.svg" alt=""/>
</button>
<InterfaceText>Font Size</InterfaceText>
<button onClick={()=>setOption('fontSize', 'larger')} className="font-size-button preventClosing">
<img src="/static/icons/enlarge_font.svg" alt="Enlarge font size" />
<button
onClick={()=>setOption('fontSize', 'larger')}
className="font-size-button preventClosing"
aria-label="Decrease font size"
>
<img src="/static/icons/enlarge_font.svg" alt=""/>
</button>
</div>
);
Expand Down
12 changes: 8 additions & 4 deletions static/js/LayoutButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useContext} from "react";
import {ReaderPanelContext} from "./context";
import {layoutOptions} from "./constants";
import {layoutOptions, layoutLabels} from "./constants";
import {InterfaceText} from "./Misc";
import PropTypes from "prop-types";

Expand Down Expand Up @@ -31,12 +31,16 @@ const LayoutButton = ({layoutOption, layoutState}) => {
const {language, textsData, setOption, layout} = useContext(ReaderPanelContext);
const path = getPath(layoutOption, layoutState, textsData);
const optionName = (language === 'bilingual') ? 'biLayout' : 'layout';
const checked = layout === layoutOption;
return (
<button
<input
key={layoutOption}
className={`layout-button ${layout === layoutOption ? 'checked' : ''}`}
className={`layout-button ${checked ? 'checked' : ''}`}
onClick={() => setOption(optionName, layoutOption)}
style={{"--url": `url(${path})`}}
role="radio"
aria-label={layoutLabels[layoutOption]}
aria-checked={checked}
/>
);
};
Expand All @@ -49,7 +53,7 @@ const LayoutButtons = () => {
const {language, textsData, panelMode} = useContext(ReaderPanelContext);
const layoutState = calculateLayoutState(language, textsData, panelMode);
return (
<div className="layout-button-line">
<div className="layout-button-line" role="radiogroup" aria-label="text layout toggle">
<InterfaceText>Layout</InterfaceText>
<div className="layout-options">
{layoutOptions[layoutState].map(option => <LayoutButton
Expand Down
2 changes: 1 addition & 1 deletion static/js/ReaderDisplayOptionsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const ReaderDisplayOptionsMenu = () => {
};

return (
<div className="texts-properties-menu">
<div className="texts-properties-menu" role="dialog">
{showLangaugeToggle() && <>
<SourceTranslationsButtons
showPrimary={showPrimary}
Expand Down
7 changes: 5 additions & 2 deletions static/js/SourceTranslationsButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ function SourceTranslationsButtons({ showPrimary, showTranslation, setShowTexts
<div
className={`button ${(isActive) ? "checked" : ""}`}
onClick={ () => setShowTexts(isPrimary, isTranslation) }
role="radio"
aria-checked={isActive}
>
<InterfaceText>{text}</InterfaceText>
<input type='radio' id={text}/>
<label for={text}><InterfaceText>{text}</InterfaceText></label>
</div>
);
}, [showPrimary, showTranslation]);
return (
<div className="show-source-translation-buttons">
<div className="show-source-translation-buttons" role="radiogroup" aria-label="Source-translation toggle">
{createButton(true, false, 'Source')}
{createButton(false, true, 'Translation')}
{!isSidePanel && createButton(true, true, 'Source with Translation')}
Expand Down
6 changes: 5 additions & 1 deletion static/js/common/ToggleSwitch.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import PropTypes from "prop-types";

function ToggleSwitch({name, disabled, onChange, isChecked}) {
function ToggleSwitch({name, disabled, onChange, isChecked, ariaLabelledBy}) {
return (
<div className="toggle-switch-container">
<div className="toggle-switch">
Expand All @@ -13,6 +13,9 @@ function ToggleSwitch({name, disabled, onChange, isChecked}) {
disabled={disabled}
onChange={onChange}
checked={isChecked && !disabled}
aria-checked={isChecked}
aria-labelledby={ariaLabelledBy}
role="switch"
/>
<label className="toggle-switch-label" htmlFor={name}>
<span className="toggle-switch-inner" />
Expand All @@ -27,5 +30,6 @@ ToggleSwitch.propTypes = {
disabled: PropTypes.bool,
onChange: PropTypes.func.isRequired,
isChecked: PropTypes.bool.isRequired,
ariaLabelledBy: PropTypes.string,
};
export default ToggleSwitch;
1 change: 1 addition & 0 deletions static/js/common/ToggleSwitchLine.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function ToggleSwitchLine({name, onChange, isChecked, text, disabled=false}) {
disabled={disabled}
onChange={onChange}
isChecked={isChecked}
ariaLabelledBy={`${name}-label`}
/>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions static/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ export const layoutOptions = {
'bi-ltr': ['stacked', 'heLeft'],
'mixed': ['stacked', 'heLeft', 'heRight'],
};
export const layoutLabels = {
'continuous': 'Show Text as a paragram',
'segmented': 'Show Text segmented',
'stacked': 'Show Source & Translation Stacked',
'heRight': 'Show RTL Text Right of LTR Text',
'heLeft': 'Show RTL Text Left of LTR Text',
}

0 comments on commit ca4f055

Please sign in to comment.