Skip to content

Conversation

@gonfunko
Copy link
Contributor

The basics

The details

Resolves

Fixes #8824

Proposed Changes

This PR adds a basic implementation of toast-style notifications to Blockly. It also adds methods to Blockly.dialog to show them, and to allow the implementation to be swapped out for an alternative by developers. The implementation is based on RaspberryPiFoundation/blockly-keyboard-experimentation#230.

@gonfunko gonfunko requested a review from a team as a code owner April 16, 2025 20:56
@gonfunko gonfunko added the PR: feature Adds a feature label Apr 16, 2025
@maribethb maribethb requested review from maribethb and removed request for rachel-fenichel April 17, 2025 20:32
core/toast.ts Outdated
toast.dataset.toastId = options.id;
toast.className = CLASS_NAME;
aria.setRole(toast, aria.Role.STATUS);
aria.setState(toast, aria.State.LIVE, 'polite');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if role alert and state assertive would be more appropriate? I'm not sure how aria decides when a polite notification should fire, but it would be unfortunate if the message goes away before it does, and it seems we are using the toasts to be more of an alert, i.e. you want to give immediate feedback that the keyboard shortcut didn't fire or something. https://sheribyrnehaber.medium.com/designing-toast-messages-for-accessibility-fb610ac364be

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know; I assumed @microbit-matt-hillsdon had good reason for choosing these values though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious to hear matt's thoughts, but you don't need to wait on this to merge

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the role is correct (at least for toasts in the general case), but there's a case to be made for assertive, and perhaps for it to be configurable on a per toast basis.

I'd review something like this with a good accessibility reputation and comprehensive implementation (support for > 1 toast is a jump in complexity though). In this case foreground toasts use "assertive" and I think a toast in response to a user action would be assertive. When we have blocks being read out it would be good to test in combination.

Tagging @kmcnaught too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went ahead and made it configurable, defaulting to polite.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I agree with role=status and polite or assertive depending on context (polite is a good default, but at some point we might want to add some examples to API docs to encourage platform developers from making good choices).

@microbit-matt-hillsdon let's start from the general policy that a toast confirming a user action (like "copied. press ctrl+v to paste") should be polite, where a toast explaining why a user action has failed (like "unable to copy this block" - hypothetically), should be assertive.

core/toast.ts Outdated
toast.dataset.toastId = options.id;
toast.className = CLASS_NAME;
aria.setRole(toast, aria.Role.STATUS);
aria.setState(toast, aria.State.LIVE, 'polite');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious to hear matt's thoughts, but you don't need to wait on this to merge

@gonfunko gonfunko merged commit c6e58c4 into RaspberryPiFoundation:rc/v12.0.0 Apr 21, 2025
7 checks passed
@gonfunko gonfunko deleted the sunbeam branch April 21, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: feature Adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants