# Adding Custom Ruleset to wagtail sa11y plugin

Source: https://djangotv.com/videos/wagtail-cms/2022/adding-custom-ruleset-to-wagtail-sa11y-plugin/
Date: 2022-10-30

## Summary

Umar Faruk shows how to add a custom accessibility ruleset to the Wagtail sa11y plugin. He extends the plugin’s custom-checks class, defines a warning message, selects gallery images with JavaScript, and checks their count. When a gallery exceeds the chosen limit, the check adds a warning border to images beyond the limit and displays a message such as “No more than 20 images should be in a single gallery page” or a per-image instruction to move the image to a new page. The example demonstrates how to use the plugin’s selectors, warning styles, and message references to create site-specific accessibility checks.

## Transcript

### [00:00] Custom Ruleset Overview

[00:00] is Umar Faruk again and I'm making this screencast to put on screw on how to make use of the SA11Y plugin and defining a custom accessibility rule set. Yeah. Just come here yeah So this is it from the web page you will actually see that you can create a custom check on the on your site. Yeah and then Yeah quite a lot of things you could explore here. You could use the induced selectors and then you could use some utility components and then

[00:45] We'll define it as a button notation and then you have the option of using this method which is this. salido root and then you can use your default JavaScript documents query selector. Yeah, and then highlight text you could use the warning highlight text or error highlight text. I think we have some sort of some of them here like Okay, we just try to go through it and then let's come here. So this is like a sample There's yeah a sample is a over using a component on a page. So you could actually use this to define maybe over

### [01:30] Gallery Image Limit

[01:30] when you use a over user component on your page and then you could use this to say okay this for nested accordion containing a form which is kind of problematic so let's just go ahead and then we'll go to our bakery demo site here so this is my bakery demo site on firefox and then We could actually see a lot here. Okay. So we just come here and Okay, very okay. So what rule set should we define? Okay, let's say I want to this is my gallery page. So I want to define a rule set to say In a ga in a single gallery page we shouldn't have more than 20 images.

[02:17] Yeah. We could you could see we have roughly it'd be 30 something here. So we don't want it. We don't want to have more than 30 something images in a gallery page. We want to have less than that. So if I should turn on my check and now you see just analyze everything without the it's not cheaping for the length of the images so let's define a co custom rule set to prepare for this. So and okay So in defining that, in the previous screencast you could remember that I had included this version, this logic here saying

### [03:03] Custom Checks Class

[03:03] the Sally custom checks. js and dots so in this file is where we define our custom rule set here And then I think I have mine cleared already. So but by default in yours you should see some predefined rule set that comes with it some sample rule sets. Yeah, that comes with it. So let's let's just go on and let's use this. So This is the class, this is a SAA11Y custom checks class. So we want to extend this class. Yeah. Want to extend this class to like data for our custom rule set

### [03:50] Warning Messages

[03:50] so we could define the error good or warning messages yeah so these are just like syntax so we could define any of this and then In this section is where we are going to define our custom messages. Yeah, so our custom messages should go within this app here and then we just say let's see let's say C is equal to and then we try to open it Yeah, so we say it's going to be announcement. Yeah, let's define it as A con

[04:35] a constant announcement. Main save. So Alright, so we just define and say okay no more than twenty images should be in a single gallery page yeah so we've defined this and then you could have multiple messages here so just say announcement message Okay, let's just use it announcement message.

### [05:21] Gallery Element Selection

[05:21] So we've defined our announcement message here and then the next thing to do is we want to define our custom rule set here. Yeah so In defining personal rule set here, what we have to do here is you could come to your browser And then let 's try to inspect to get the class currently. Yeah. So we could just come and then say I try to Right again okay. So let's try to take a focus. Okay, so well that's interesting. It's carrying it's And on other lists carrying

[06:07] several list items. Yeah. So it's made it more interesting. We just need to say this on other list shouldn't take more than 10 items or 20 items, right? So what's the class? List limits? Alright. Okay. So let's just come back to Let's come back to our where we are defining custom checks and then we'll say constant check gallery is equal to these S And then so I'm not I'm not like picking it off my head.

[06:53] That's part of what we get from the SA10Y site. So we could actually extend this and then let's say we try to pick this yeah. So let's speak that and then come here by saying Yeah, so It's interesting. Let's say we want to extend this class and if we just try to extend the class, so we say UL dot Listening, there 's voice, that's images And I'm sure we are all

### [07:38] Rule Logic and Iteration

[07:38] like pretty familiar with this. Concept in JavaScript. So I'm just picking the classes. It's not I'm not picking anything special. It's more parallel yes. on other list so having the listing images and then we pick the LI classes so it's not like I'm picking something new okay so we've defined our variable called check gallery and then we want to locate this and after that we can have an add the conditional statement here we say So how do we say so we try to get the length

[08:24] and then return the length to be fine here? So this one If this dot length is greater than twenty, at least twenty, it's extended Yeah, so if it's greater than ten then we it trade through each of them and we try to add some interesting border around it okay so I define my follow here and then I say let I recur to tenth? Yeah. So we want to start from the tenth item, yeah.

[09:10] And When we start from the 10th item, let's say let's i is equal to 10 and i sorry i is less than Check gallery oops I forgot to say to gallery dot length and then the I was yeah. So we have that, so we've initialized our what's the name? We've initialized our loop We've set it to start from the 10th item and then till the max and then

### [09:56] Warning Highlighting

[09:56] equate. So in the next sense when you say okay, the Check gallery at I dot so we will now want to add the SA10Y classes so let's come back here say okay what can we add the class list dot so we want to add the border so we come back here then we say Yeah so we want to add the actual we are we shouldn't add the error border it should be a warning border So I think we have the logic for that. Yeah, so this is a warning border. You want to add a warning

[10:41] border to it and then You just copy it down here and then bam. Okay, so we have it and the next thing is you want to add the section for our message saying okay maybe you want you to add this message down here so I'll just try to explain everything One after the other. Okay. So this is what we are getting there and then let 's just try to bring it right there. We say so what do we do next? Say

[11:27] it's try to adjust these and then So we try to eject this and try to adjust this also. Yeah, and then Alright, so we've tried to adjust them. It's now remaining for us to ship it back to Alright, I love to use this object reference in as I love to use it as the what 's the name Okay, so this path before I clean it this is saying. warning but we didn't define a warning message in an object so we just call it directly because we define it as a constant here

[12:16] So we'll just call a warning message here. Bam. So this is referencing that here we want this kind of we want to display a warning message. So This should come as a warning to get and then the next thing is warning message here so I don't really like this though we might use it also but let's just use the dots object referencing so just pick dot announcement message if this did you see dot announcement message and then If we happen to define this constant, the error warning or good values in a in an object then we could actually use this notation also.

[13:01] Let's just pick it like this and try to save. So let's go by it again and then see what else do we have So we've successfully picked the cap here and then say all these icons in that class So say once it's greater than 10, start from the 11th item since I yeah an array always starts from zero. So start from the 11th item till the last item you create keep increasing and then what you need to do the is you add the class for Sally one in border Oh yeah, we made a mistake here. So this is you know we copied this from

### [13:47] Custom Check Results

[13:47] The SA11Y site, so we should change it to ours and then we should be it. So let's see on iterating keep adding this warning butter to each images and then displaying this warning messages to them. So let's try to save that and Let's go back to our page to see. I'll just try to replace and then try to see if it's actually work Okay, so we can see now let's try to open our SA111. Oh this is cool. So you can actually see that okay. From the tenth item we have the yellow border. Saying no more than 20 images should be in a single gallery page.

### [14:35] Actionable Warning Text

[14:35] This is coming as a warning message. Let's try to push this up. We have confirmed that our custom text is now there. Let's try to push this up and try to extend our images extend our warning message to say please move image so i to a to a new page. So let's try to save that. So here we say please move the image, the current image to a new page. Try to spice things up and check what we have. So again you can see

[15:21] this move image 10 to a new bit or it's now displaying nice. So let's try it Leave some spaces there. Okay. Then I sit again. Try to refresh and then What we see here now is please move image 10 to a new page, please move image 12 to a new page, move image 14 Move image 15 which is this to a new page and then we'll get to the last item please move image 28 to a new page So this is interesting. We've successfully defined a custom text for our SA11Y plugin and I think you could actually take the most out of it.

[16:10] Thank you very much for listening to me once again, Emma Mark Park.
