-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Show notice on save in site editor #36897
Conversation
Size Change: +98 B (0%) Total Size: 1.11 MB
ℹ️ View Unchanged
|
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.
Thank you! This looks great.
I tested, and it works as expected.
In the below videos, I tested first by clicking the Save button twice, then by using CMD+S, followed by the return key, pressing the tab key after to see if the next focus targets would be the same. The next target for tab was the same both before and after applying the PR, as expected.
Before:
Before.Save.Notice.mov
After:
After.Save.Notice.mov
965c1f6
to
1c2b3aa
Compare
); | ||
} | ||
|
||
Promise.all( pendingSavedRecords ).then( ( values ) => { |
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.
Could pendingSavedRecords
fail? Might be easy enough to also add catch
to handle it with error notices too.
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.
pendingSavedRecords
is an array of the results of calling saveEntityRecord
, which afaik never returns an error, just a record or undefined
. That's why I'm checking for 'undefined' when showing the failure notice. Would it still be worth adding a catch
in this case? We wouldn't really be doing anything with the caught error.
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.
That's a bit unexpected TBH, why wouldn't saveEntityRecord
throw an error if it... errors? I guess adding a catch
case does no harm either, in case we want to revisit the behavior of saveEntityRecord
.
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.
I'm not sure what the history behind this is, but the savePost function accounts for it by fetching errors in a super roundabout way. I'm guessing any changes to saveEntityRecord
at this point would require a fair bit of refactoring anyway 😅
Not to say we can't add in a catch
here, it won't hurt to do so. But we'll still have to generate the failure notices based on undefined
as the return value too.
2badc1d
to
a40b80f
Compare
b2ffb98
to
bb324ba
Compare
I merged a fix for the unit test issue - #36987 |
@tellthemachines The notice is announced for me. It says "Site updated." Looks like it uses @wordpress/a11y.speak(). If some screen readers don't announce, you may need to force "assertive" as second parameter to that function. However, it seems to use this in the module you imported I guess, not directly. createSuccessNotice. |
bb324ba
to
5bbcc41
Compare
Tested with NVDA on Windows in Chrome and Firefox. The successful update and the failure are announced in both browsers. |
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.
Oh hey I also pushed some commits here so I obviously approve it 😆 . I'm not cheating.
* Show notice on save in site editor Co-authored-by: Kai Hao <[email protected]>
Description
Fixes #36166. Adds notices on success and failure to the Save action in the site editor.
How has this been tested?
In the site editor, make changes to one or two template parts and click save. Check that a snackbar pops up when save is successful.
Make some more changes and set network to "offline". Saving again should cause an error notice to appear.
Repeat this process using a screen reader, and check that the notices are read by the screen reader when they pop up.
I tested this with VoiceOver in Safari, Firefox and Chrome. Safari and Chrome announce the notices correctly, but Firefox only announces the failure notice. It seems to ignore the snackbar altogether.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).