Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does react-modal require the prop contentLabel?

I started getting this warning on my react-modal components:

Warning: Failed propType: Required prop contentLabel was not specified in Modal.

It doesn't prevent the modal from working correctly, I just see the warning in the dev tools console. I can pass this prop in by specifying some random string, but I do not understand what this is actually used for, and why it is required.

like image 776
evianpring Avatar asked Dec 27 '16 12:12

evianpring


People also ask

How do you use modal dialog in react?

The dialog can be closed by clicking on the overlay or by hitting the ESC key. The react-modal takes care of positioning the dialog and displaying an overlay. We start by importing the Modal component from react-modal . Everything that goes inside the Modal component will be rendered as a modal dialog.

What is modal component in react?

The modal component provides a solid foundation for creating dialogs, lightboxes, popovers, etc. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Modal Component in ReactJS using the following approach. Creating React Application And Installing Module.

How do I make a responsive modal react?

You can just add class/ID to your Modal and/or its child DOM, then use a normal CSS file, with @medi a declaration, and style your component responsively as you wish! You can simply include that normal CSS file in your main index. html file.


1 Answers

contentLabel improves accessibility. You probably don't notice it, but in certain situations this prop can help your users understand what the modal is about. From their repository:

The Modal object has two required props:

  • isOpen to render its children.
  • contentLabel to improve a11y, since v1.6.0.

The value of contentLabel is set as an aria-label on the modal element. This helps assistive technology, like screen readers, to add a label to an element that would otherwise be anonymous. People with visual impairment for example can make more sense out of your modal when added.

like image 184
Fabian Schultz Avatar answered Oct 28 '22 06:10

Fabian Schultz