-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix nbsphinx color outputs, suppress other notebook output Axe errors #1905
Fix nbsphinx color outputs, suppress other notebook output Axe errors #1905
Conversation
Submitting this as a draft until I can hunt down what seems to be some kind of race condition (I'm guessing race condition because sometimes the tests pass locally, sometimes not). Sometimes when running the tests locally, the "scollable-region-focusable" Axe check fails, which shouldn't happen because I am asking Playwright to wait for a sign from the script that adds tabindex=0. |
Getting same confusing Axe failure in CI |
a66f1e3
to
7354230
Compare
I think I found the cause of the race condition:
With that order of operations, we get a failure for the scrollable-region-focusable Axe check. But if step 5 comes after 6, the check passes. I rewrote the Playwright script to wait both for the ipywidget table's container to load and for tabindex="0" to be applied. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
@@ -52,6 +52,28 @@ div.nblast.container { | |||
margin-bottom: 1rem; | |||
} | |||
|
|||
// Notebook cell input line number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Notebook cell input line number | |
// Notebook cell input prompt (execution count) | |
// Ref: https://nbformat.readthedocs.io/en/latest/format_description.html#code-cells |
} | ||
} | ||
|
||
// Notebook cell output line number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Notebook cell output line number | |
// Notebook cell output prompt (execution count) | |
// Ref: https://nbformat.readthedocs.io/en/latest/format_description.html#code-cells |
# TODO: for color contrast issues with common notebook outputs | ||
# (ipywidget tabbed panels, Xarray, etc.), should we override | ||
# third-party CSS with our own CSS or/and work with NbSphinx, MyST-NB, | ||
# ipywidgets, and other third parties to use higher contrast colors in | ||
# their CSS? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @trallard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Larger conversation but longer term it would be best to have these fixed upstream vs in here.
Not sure how much of an effort this would be so will have to pin this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
html[data-theme="dark"] & { | ||
color: #ffa07a; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: check MyST-NB notebook prompts for color contrast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -38,8 +38,9 @@ def filter_ignored_violations(violations, url_pathname): | |||
]: | |||
filtered = [] | |||
for violation in violations: | |||
# TODO: eventually fix this rule violation. See | |||
# https://github.com/pydata/pydata-sphinx-theme/issues/1479. | |||
# TODO: remove this exclusion once the following update to Axe is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to the rest of the PR, but I thought I would go ahead make this comment more up to date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CSS additions to this file override nbsphinx styles for the notebook cell prompts, which don't have sufficient color contrast against our light and dark backgrounds.
Nbsphinx uses a shade of blue for the input cell prompt and a shade of red for the output cell prompt. So I chose blueish and reddish colors from the following two accessible-pygments themes:
TODO: add this as a code comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, added comments to the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gabalafou this looks good, I checked through the axe/playwright tests and they look good so I will go ahead and merge
@@ -167,6 +168,13 @@ def test_axe_core( | |||
# Wait for CSS transitions (Bootstrap's transitions are 300 ms) | |||
page.wait_for_timeout(301) | |||
|
|||
# On the PyData Library Styles page, wait for ipywidget to load and for our | |||
# JavaScript to apply tabindex="0" before running Axe checker (to avoid | |||
# false positives for scrollable-region-focusable). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I did not notice before that this was the case, i.e. the tabindex
being applied later. I suppose it make sense since we are delegating this to JS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you might have seen my first tab stop implementation, which adds tabindex="0" at build time (via HTML created by Python), and might not have noticed my second tab stop implementation, which adds a zero tab index at run time (via DOM manipulation by JavaScript).
Fun fact. This change was driven by an article you shared (or maybe it was Smera) 🌻 Inclusive Components - Data Tables - Only Focusable Where Scrollable
# TODO: for color contrast issues with common notebook outputs | ||
# (ipywidget tabbed panels, Xarray, etc.), should we override | ||
# third-party CSS with our own CSS or/and work with NbSphinx, MyST-NB, | ||
# ipywidgets, and other third parties to use higher contrast colors in | ||
# their CSS? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Larger conversation but longer term it would be best to have these fixed upstream vs in here.
Not sure how much of an effort this would be so will have to pin this for now.
Once this PR is merged, running the accessibility checks should execute successfully, with all known failures marked as expected. This should allow us to close #1428 and add the accessibility checks to CI.