Skip to content
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

LG-15064: Countdown alerts for expiring phone OTP announces too frequently #11899

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion app/components/countdown_alert_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class CountdownAlertComponent < BaseComponent
attr_reader :show_at_remaining, :alert_options, :countdown_options, :tag_options
attr_reader :show_at_remaining, :alert_options, :countdown_options,
:tag_options

def initialize(
show_at_remaining: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class OtpVerificationController < ApplicationController
include TwoFactorAuthenticatable
include MfaSetupConcern
include NewDeviceConcern
include SessionTimeoutWarningHelper

before_action :confirm_multiple_factors_enabled
before_action :redirect_if_blank_phone, only: [:show]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import './countdown-element';
describe('CountdownAlertElement', () => {
const sandbox = useSandbox({ useFakeTimers: true });

function createElement({ showAtRemaining }: { showAtRemaining?: number } = {}) {
function createElement({
showAtRemaining,
screenReaderFrequency,
}: { showAtRemaining?: number; screenReaderFrequency?: number } = {}) {
document.body.innerHTML = `
<lg-countdown-alert ${showAtRemaining ? `show-at-remaining="${showAtRemaining}"` : ''}>
<lg-countdown-alert ${showAtRemaining ? `show-at-remaining="${showAtRemaining}"` : ''} ${
screenReaderFrequency ? `screen-reader-frequency="${screenReaderFrequency}"` : ''
}>
<div class="usa-alert usa-alert--info margin-bottom-4 usa-alert--info-time" role="status">
<div class="usa-alert__body">
<p class="usa-alert__text">
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/packages/countdown/countdown-alert-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class CountdownAlertElement extends HTMLElement {

show() {
this.classList.remove('display-none');
if (this.showAtRemaining) {
this.querySelector('lg-countdown')?.setAttribute('aria-live', 'off');
}
}
}

Expand Down
18 changes: 13 additions & 5 deletions app/views/two_factor_authentication/otp_verification/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
<% end %>

<% if @presenter.otp_expiration.present? %>
<%= render CountdownAlertComponent.new(
show_at_remaining: IdentityConfig.store.otp_expiration_warning_seconds.seconds,
alert_options: { class: 'margin-bottom-4' },
countdown_options: { expiration: @presenter.otp_expiration },
) %>
<%= render CountdownAlertComponent.new(
show_at_remaining: IdentityConfig.store.otp_expiration_warning_seconds.seconds,
alert_options: { class: 'margin-bottom-4' },
countdown_options: { expiration: @presenter.otp_expiration },
) %>

<p class="usa-sr-only" role="timer" aria-live="polite" aria-atomic="true">
<%= render CountdownComponent.new(
expiration: @presenter.otp_expiration,
update_interval: 30.seconds,
start_immediately: true,
) %>
</p>
<% end %>

<%= render PageHeadingComponent.new.with_content(@presenter.header) %>
Expand Down