Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep the length hint live regions mounted

Yudhi Armyndharisf5d00d4659eb
diff --git a/dashboard/src/components/chats/StatusComposeModal.test.ts b/dashboard/src/components/chats/StatusComposeModal.test.ts
index 1bdb3484a..4e097310b 100644
--- a/dashboard/src/components/chats/StatusComposeModal.test.ts
+++ b/dashboard/src/components/chats/StatusComposeModal.test.ts
@@ -181,9 +181,11 @@ test('status text and caption are bounded by Post, not truncated by UTF-16 units
fireEvent.change(text, { target: { value: '\u{1F600}'.repeat(4096) } });
assert.equal(post.disabled, false, 'text the gateway accepts is held');
assert.equal(screen.queryByText('Limited to 4096 characters (4096 now).'), null);
+ // A live region mounted together with its text is often not announced, so each hint fills one already there.
+ let regions = screen.queryAllByRole('status');
fireEvent.change(text, { target: { value: '\u{1F600}'.repeat(4097) } });
assert.equal(post.disabled, true, 'text over 4096 characters can be posted');
- screen.getByText('Limited to 4096 characters (4097 now).');
+ assert.ok(regions.includes(screen.getByText('Limited to 4096 characters (4097 now).')));
fireEvent.click(screen.getByRole('button', { name: 'Image' }));
fireEvent.change(screen.getByLabelText('Status image'), {
@@ -194,7 +196,8 @@ test('status text and caption are bounded by Post, not truncated by UTF-16 units
assert.equal(caption.hasAttribute('maxlength'), false);
fireEvent.change(caption, { target: { value: '\u{1F600}'.repeat(1024) } });
assert.equal(post.disabled, false, 'a caption the gateway accepts is held');
+ regions = screen.queryAllByRole('status');
fireEvent.change(caption, { target: { value: '\u{1F600}'.repeat(1025) } });
assert.equal(post.disabled, true, 'a caption over 1024 characters can be posted');
- screen.getByText('Limited to 1024 characters (1025 now).');
+ assert.ok(regions.includes(screen.getByText('Limited to 1024 characters (1025 now).')));
});
diff --git a/dashboard/src/components/chats/StatusComposeModal.tsx b/dashboard/src/components/chats/StatusComposeModal.tsx
index bf4830221..1571a5266 100644
--- a/dashboard/src/components/chats/StatusComposeModal.tsx
+++ b/dashboard/src/components/chats/StatusComposeModal.tsx
@@ -218,11 +218,10 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {
onChange={e => setComposeText(e.target.value)}
placeholder={t('chats.status.composeText')}
/>
- {composeTextLength > 4096 && (
- <p className="input-hint" role="status">
- {t('common.fieldTooLong', { max: 4096, count: composeTextLength })}
- </p>
- )}
+ {/* Kept mounted, unstyled while empty: a live region inserted with its text is often not announced. */}
+ <span className={composeTextLength > 4096 ? 'input-hint' : undefined} role="status">
+ {composeTextLength > 4096 ? t('common.fieldTooLong', { max: 4096, count: composeTextLength }) : ''}
+ </span>
</div>
<div className="compose-row">
<div className="compose-field">
@@ -280,11 +279,9 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {
value={composeCaption}
onChange={e => setComposeCaption(e.target.value)}
/>
- {composeCaptionLength > 1024 && (
- <p className="input-hint" role="status">
- {t('common.fieldTooLong', { max: 1024, count: composeCaptionLength })}
- </p>
- )}
+ <span className={composeCaptionLength > 1024 ? 'input-hint' : undefined} role="status">
+ {composeCaptionLength > 1024 ? t('common.fieldTooLong', { max: 1024, count: composeCaptionLength }) : ''}
+ </span>
</div>
</>
)}
diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.ts
index 98ff8432b..682490e75 100644
--- a/dashboard/src/pages/ApiKeys.test.ts
+++ b/dashboard/src/pages/ApiKeys.test.ts
@@ -224,9 +224,11 @@ test('a key name over the 100 characters the gateway takes keeps Create disabled
assert.equal(name.hasAttribute('maxlength'), false);
fireEvent.change(name, { target: { value: '\u{1F511}'.repeat(100) } });
assert.equal(create.disabled, false, 'Create is disabled for a 100-character name');
+ const regions = screen.queryAllByRole('status');
fireEvent.change(name, { target: { value: '\u{1F511}'.repeat(101) } });
assert.equal(create.disabled, true, 'Create is enabled for a 101-character name');
- screen.getByText('Limited to 100 characters (101 now).');
+ // A live region mounted together with its text is often not announced, so the hint fills one already there.
+ assert.ok(regions.includes(screen.getByText('Limited to 100 characters (101 now).')));
});
test('an IP or chat line the gateway would refuse keeps Create disabled and names the line', async () => {
diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsx
index 911b140d0..5c231a111 100644
--- a/dashboard/src/pages/ApiKeys.tsx
+++ b/dashboard/src/pages/ApiKeys.tsx
@@ -579,11 +579,10 @@ export function ApiKeys() {
{newKey.name.length > 0 && nameTooShort && (
<span className="key-field-hint">{t('apiKeys.nameTooShort')}</span>
)}
- {nameTooLong && (
- <span className="key-field-hint" role="status">
- {t('common.fieldTooLong', { max: 100, count: nameLength })}
- </span>
- )}
+ {/* Kept mounted, unstyled while empty: a live region inserted with its text is often not announced. */}
+ <span className={nameTooLong ? 'key-field-hint' : undefined} role="status">
+ {nameTooLong ? t('common.fieldTooLong', { max: 100, count: nameLength }) : ''}
+ </span>
<label htmlFor="ak-2">{t('common.role')}</label>
<select
id="ak-2"