Skip to content

Commit

Permalink
Merge pull request #25 from hmrc/accessibility/warnings_and_info_mess…
Browse files Browse the repository at this point in the history
…ages

Add ability to update content description for InformationMessageCardView
  • Loading branch information
jemmaSlater authored Mar 1, 2021
2 parents c260fe4 + 19abc0a commit c8243f2
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Allowed headings:

## [Unreleased]

### Added

* Added ability for `InformationMessageCardView` to add a custom content description to headline

## [3.8.0] - 2021-02-04

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ If you need padding on your dividers, you can set `android:dividerPadding="@dime
android:layout_height="wrap_content"
android:layout_margin="@dimen/hmrc_spacing_16"
app:headline="@string/info_message_placeholder_headline"
app:headlineContentDescription="@string/headlineContentDescription"
app:headlineIcon="@drawable/ic_info"
app:type="urgent" />
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class WarningView @JvmOverloads constructor(

fun setText(@StringRes id: Int) = setText(context.getString(id))

fun updateContentDescription(textContentDescription: String) {
contentDescription = textContentDescription
}

fun setTextColor(@ColorRes textColor: Int) {
binding.text.setTextColor(ContextCompat.getColor(context, textColor))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ class InformationMessageCardView @JvmOverloads constructor(
}

init {

attrs?.let { attributeSet ->
val typedArray = context.theme
.obtainStyledAttributes(attributeSet, R.styleable.InformationMessageCardView, 0, 0)
setHeadline(typedArray.getString(R.styleable.InformationMessageCardView_headline))
typedArray.getString(R.styleable.InformationMessageCardView_headlineContentDescription)?.let {
setHeadlineContentDescription(it)
}
setHeadlineIcon(typedArray.getResourceId(R.styleable.InformationMessageCardView_headlineIcon, NO_ICON))
val typeOrdinal = typedArray.getInt(R.styleable.InformationMessageCardView_type, -1)
if (typeOrdinal != -1) {
Expand All @@ -71,6 +73,10 @@ class InformationMessageCardView @JvmOverloads constructor(
binding.warningView.setText(headline)
}

fun setHeadlineContentDescription(contentDesc: String) {
binding.warningView.updateContentDescription(contentDesc)
}

fun setHeadlineIcon(resId: Int) {
binding.warningView.setIcon(resId)
}
Expand Down
2 changes: 2 additions & 0 deletions components/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@
<declare-styleable name="InformationMessageCardView">
<!-- Headline to display at top of card. -->
<attr name="headline" />
<!-- Headline content description. -->
<attr name="headlineContentDescription" />
<!-- Icon to display next to the headline text. -->
<attr name="headlineIcon" format="reference" />
<!-- Type of message -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class InformationMessageCardFragment : BaseComponentsFragment() {
SecondaryButton(requireContext()).apply { setText(R.string.info_message_placeholder_headline_button) }
))

binding.infoMessageExample1
.setHeadlineContentDescription(getString(R.string.info_message_example_1_headline_content_description))

binding.infoMessageExample2.setHeadlineButtons(listOf(
SecondaryButton(requireContext()).apply { setText(R.string.info_message_example_2_button) }
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
android:layout_margin="@dimen/hmrc_spacing_16"
app:type="notice"
app:headline="@string/info_message_example_3_headline"
app:headlineContentDescription="@string/info_message_example_3_headline_content_description"
app:headlineIcon="@drawable/components_ic_warning" />

</LinearLayout>
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,13 @@
<string name="info_message_placeholder_headline">Headline</string>
<string name="info_message_placeholder_headline_button">Headline button</string>
<string name="info_message_example_1_headline">Info message</string>
<string name="info_message_example_1_headline_content_description">Info message content description</string>
<string name="info_message_example_1_button_primary">A primary action</string>
<string name="info_message_example_1_button_secondary">A secondary action</string>
<string name="info_message_example_2_headline">Warning message</string>
<string name="info_message_example_2_button">Do something</string>
<string name="info_message_example_3_headline">Notice message</string>
<string name="info_message_example_3_headline_content_description">Notice message content description</string>

<!-- Menu Panel Row View -->
<string name="menu_panel_placeholder_title">Title</string>
Expand Down

0 comments on commit c8243f2

Please sign in to comment.