Skip to content

Add custom display delay support #3

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ To include a close button for each message, add the following to your Django set
DJANGO_MESSAGES_DISPLAY_CLOSE_BUTTON = True
```

To change message display delay from default 5000ms, add the following to your Django settings:
```python
DJANGO_MESSAGES_DISPLAY_DELAY = 10000
```


## Accessibility
The notifications have the relevant attributes so that screen readers announce each one without interrupting the user's flow.
Even though the notifications visually disappear after a certain amount of time, they remain in the document to be accessible by screen readers on demand.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

messageElements.forEach((element, index) => {
const showDelay = index * 75;
const hideDelay = showDelay + 5000;
const hideDelay = showDelay + {% if delay %}{{ delay }}{% else %}5000{% endif %};

setTimeout(() => {
element.classList.remove('hidden');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ def django_messages_display(context):
include_close_button = getattr(
settings, "DJANGO_MESSAGES_DISPLAY_CLOSE_BUTTON", None
)

delay = getattr(
settings, "DJANGO_MESSAGES_DISPLAY_DELAY", None
)
messages = context.get('messages', [])

render_context = {
"include_close_button": include_close_button,
"delay": delay,
"messages": messages,
}

Expand Down