@@ -147,6 +147,60 @@ const restrictedSyntaxComponents = [
147147 message :
148148 '`disabled` used without the `accessibleWhenDisabled` prop. Disabling a control without maintaining focusability can cause accessibility issues, by hiding their presence from screen reader users, or preventing focus from returning to a trigger element. (Ignore this error if you truly mean to disable.)' ,
149149 } ,
150+ // Rules to find tooltip usage that needs reviewing.
151+ {
152+ // All tooltips
153+ selector : `JSXOpeningElement[name.name="Tooltip"]` ,
154+ message :
155+ 'Tooltip needs to have its anchor checked to make sure it has an accessible description if needed' ,
156+ } ,
157+ ...[
158+ 'Tooltip' ,
159+ 'ToolbarButton' ,
160+ 'ToolbarDropdownMenu' ,
161+ 'DropdownMenu' ,
162+ ] . map ( ( componentName ) => ( {
163+ selector : `JSXOpeningElement[name.name="${ componentName } "]:not(:has(JSXAttribute[name.name="__nextHasNoMarginBottom"]))` ,
164+ message :
165+ componentName +
166+ ' needs to have its anchor checked to make sure it has an accessible description if needed.' ,
167+ } ) ) ,
168+ {
169+ // All Button s with a `label` and no explicit `showTooltip={false}` (includes the ones with no children)
170+ selector : `JSXOpeningElement[name.name="Button"]:not(:has(JSXAttribute[name.name="showTooltip"][value.expression.value!=true])):has(JSXAttribute[name.name="label"])` ,
171+ message :
172+ 'Button needs to be checked to make sure it has an accessible description if needed' ,
173+ } ,
174+ {
175+ // All Button s with a `shortcut`
176+ selector : `JSXOpeningElement[name.name="Button"]:has(JSXAttribute[name.name="shortcut"])` ,
177+ message :
178+ 'Button needs to be checked to make sure it has an accessible description if needed' ,
179+ } ,
180+ {
181+ // All Buttons with a description prop
182+ selector : `JSXOpeningElement[name.name="Button"]:has(JSXAttribute[name.name="description"])` ,
183+ message :
184+ 'Button needs to be checked to make sure it has an accessible description if needed' ,
185+ } ,
186+ {
187+ // All Buttons with a describedBy prop
188+ selector : `JSXOpeningElement[name.name="Button"]:has(JSXAttribute[name.name="describedBy"])` ,
189+ message :
190+ 'Button needs to be checked to make sure it has an accessible description if needed' ,
191+ } ,
192+ {
193+ // All Buttons with a aria-describedby prop
194+ selector : `JSXOpeningElement[name.name="Button"]:has(JSXAttribute[name.name="aria-describedby"])` ,
195+ message :
196+ 'Button needs to be checked to make sure it has an accessible description if needed' ,
197+ } ,
198+ {
199+ // All Buttons with a aria-label prop
200+ selector : `JSXOpeningElement[name.name="Button"]:has(JSXAttribute[name.name="aria-label"])` ,
201+ message :
202+ 'Button needs to be checked to make sure it has an accessible description if needed' ,
203+ } ,
150204] ;
151205
152206module . exports = {
0 commit comments