Skip to main content

Config file

In dev mode, AMA components try to enforce some accessibility requirements by showing an error banner and printing the reason when a rule is broken. For example, missing accessibility label, poor color contrast, minimum size not met, etc.

Conscious that there might be edge cases where a rule or two might need to be broken, AMA provides a way to change the logging level of each guideline tested.

info

The library does not perform any accessibility check on the production build!

The log levels

AMA guidelines are categorised as:

  • MUST and MUST_NOT: Those best practices are enforced and AMA overlays an error when fail
  • SHOULD and SHOULD_NOT: Those best practices are preferred and AMA prints only prints a warning message when fail

Default Rules

Log keyGuideline
BOTTOM_SHEET_CLOSE_ACTIONMUST
CONTRAST_FAILEDMUST
CONTRAST_FAILED_AAASHOULD
FLATLIST_NO_COUNT_IN_SINGULAR_MESSAGESHOULD
FLATLIST_NO_COUNT_IN_PLURAL_MESSAGEMUST
MINIMUM_SIZEMUST
NO_ACCESSIBILITY_LABEL1MUST
NO_ACCESSIBILITY_ROLE 1MUST
NO_FORM_LABELMUST
NO_FORM_ERRORMUST
NO_KEYBOARD_TRAP 1MUST_NOT
UPPERCASE_TEXT_NO_ACCESSIBILITY_LABELMUST_NOT
NO_UPPERCASE_TEXTMUST_NOT

Constants

Elements that perform a contrast check do it on all the children up to the level specified by CONTRAST_CHECKER_MAX_DEPTH.

Constant keyDefault value
CONTRAST_CHECKER_MAX_DEPTH5

This can be turned off by specifying a level of 0

accessibilityLabelExceptions

This field is empty by default and can be overridden by specifying a list of accessibilityLabel to be excluded from the all caps check.

Customising the log levels

Create a JSON file called ama.json in the project's root folder to customise the log rules, then specify the custom log level for the wanted key.

Example

{
"rules": {
"CONTRAST_FAILED": "warn",
"CONTRAST_CHECKER_MAX_DEPTH": 0
},
"accessibilityLabelExceptions": ["A A"]
}
tip

The JSON file does not need to contain all the log keys, as AMA defaults to the default rule if not present in the JSON one.

warning

Every time the ama.rules.json file is updated, you need to update the copy inside the node_modules folder and restart the development server:

cp ama.rules.json node_modules/react-native-ama/

yarn start

  1. The rule cannot be overridden