Skip to content

Commit

Permalink
MDL-78282 output: new sr_text renderer method
Browse files Browse the repository at this point in the history
Some output classes require pre-rendered elements. In some cases, those
elements require some screen reader extra texts (especially in buttons).
The st_text method allow the outputs to create those inline tags without
using html_writer. Furthermore, the current screen reader classes are
based on bootstrap, having them isolated in renderer methods allow
themes to implement alternatives accessibility HTML structures.
  • Loading branch information
ferranrecio committed Jul 26, 2023
1 parent 01e0e56 commit a586e95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3277,6 +3277,20 @@ public function paragraph(string $contents, ?string $classes = null, ?string $id
);
}

/**
* Outputs a screen reader only inline text.
*
* @param string $contents The contents of the paragraph
* @return string the HTML to output.
*/
public function sr_text(string $contents): string {
return html_writer::tag(
'span',
$contents,
['class' => 'sr-only']
) . ' ';
}

/**
* Outputs a container.
*
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ information provided here is intended especially for developers.
the page displays a heading for the activity (usually a h2 heading containing the activity name).
* New method moodleform::filter_shown_headers() is created to show some expanded headers only and hide the rest.
* count_words() and count_letters() have a new optional parameter called $format to format the text before doing the counting.
* New core_renderer::sr_text method to generate screen reader only inline texts without using html_writter.

=== 4.2 ===

Expand Down

0 comments on commit a586e95

Please sign in to comment.