Skip to content

Prevent toast disappearing when hovered - #227

Merged
dubstar-04 merged 1 commit into
mainfrom
feature/toast-hover
Apr 7, 2026
Merged

Prevent toast disappearing when hovered#227
dubstar-04 merged 1 commit into
mainfrom
feature/toast-hover

Conversation

@dubstar-04

Copy link
Copy Markdown
Owner

Fixes #226

@dubstar-04
dubstar-04 requested a review from Copilot April 7, 2026 05:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Addresses issue #226 by preventing the command-line/toast overlay from disappearing while the user is hovering it, shifting toast dismissal responsibility to the Toast component so it can pause/resume timers based on hover state.

Changes:

  • Moved toast auto-dismiss logic out of DesignWeb.showToast into the Toast component (centralized timer management).
  • Added hover handling to pause dismissal on mouseenter and re-schedule dismissal on mouseleave.
  • Enabled pointer interaction on the toast element so hover events can be received.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/js/DesignWeb.js Removes inline setTimeout dismissal and exposes removeToast(id); passes it into Toast.
src/js/components/toast.js Implements per-toast timers, hover pause/resume behavior, and cleanup on unmount/update.
src/css/Toast.css Allows toast elements to receive pointer events (required for hover).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +56
const DISMISS_DELAY = 3000;
const HOVER_DISMISS_DELAY = 1000;

export default class Toast extends Component {
constructor(props) {
super(props);
this.timers = new Map();
}

componentDidMount() {
this.startTimersForNewToasts([], this.props.toasts);
}

componentDidUpdate(prevProps) {
this.startTimersForNewToasts(prevProps.toasts, this.props.toasts);
// Clear timers for toasts that were removed externally
prevProps.toasts.forEach((toast) => {
if (!this.props.toasts.find((t) => t.id === toast.id)) {
clearTimeout(this.timers.get(toast.id));
this.timers.delete(toast.id);
}
});
}

componentWillUnmount() {
this.timers.forEach((timerId) => clearTimeout(timerId));
this.timers.clear();
}

startTimersForNewToasts(prevToasts, nextToasts) {
nextToasts.forEach((toast) => {
if (!this.timers.has(toast.id) && !prevToasts.find((t) => t.id === toast.id)) {
this.scheduleDismiss(toast.id, DISMISS_DELAY);
}
});
}

scheduleDismiss(id, delay) {
const timerId = setTimeout(() => {
this.timers.delete(id);
this.props.removeToast(id);
}, delay);
this.timers.set(id, timerId);
}

handleMouseEnter(id) {
clearTimeout(this.timers.get(id));
this.timers.delete(id);
}

handleMouseLeave(id) {
this.scheduleDismiss(id, HOVER_DISMISS_DELAY);
}

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

New hover-pausing / rescheduled dismissal behavior is implemented here, but there’s no automated test covering it. Consider adding a React Testing Library/Jest test that (1) verifies a toast does not dismiss while hovered when timers are advanced and (2) dismisses after mouse leave once timers are advanced again, to prevent regressions for issue #226.

Copilot uses AI. Check for mistakes.
@dubstar-04
dubstar-04 marked this pull request as ready for review April 7, 2026 05:54
@dubstar-04
dubstar-04 merged commit 0464b3d into main Apr 7, 2026
5 checks passed
@dubstar-04
dubstar-04 deleted the feature/toast-hover branch April 7, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command line information overlay disappears even when cursor is hovering over it

2 participants