Skip to content

Commit c07c470

Browse files
authored
[PM-29654] Hide copy button when custom field has no value (#20459)
* Hide copy buttone when there is no value * Added no value entered to the screenreader
1 parent 84a4bdb commit c07c470

5 files changed

Lines changed: 37 additions & 13 deletions

File tree

apps/browser/src/_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5142,6 +5142,10 @@
51425142
}
51435143
}
51445144
},
5145+
"noValueEntered": {
5146+
"message": "No value entered",
5147+
"description": "Screen reader announcement appended to a custom field's name when the field has no value entered."
5148+
},
51455149
"noValuesToCopy": {
51465150
"message": "No values to copy"
51475151
},

apps/desktop/src/locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,10 @@
12251225
"noItemsInList": {
12261226
"message": "There are no items to list."
12271227
},
1228+
"noValueEntered": {
1229+
"message": "No value entered",
1230+
"description": "Screen reader announcement appended to a custom field's name when the field has no value entered."
1231+
},
12281232
"sendVerificationCode": {
12291233
"message": "Send a verification code to your email"
12301234
},

apps/web/src/locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,10 @@
14321432
}
14331433
}
14341434
},
1435+
"noValueEntered": {
1436+
"message": "No value entered",
1437+
"description": "Screen reader announcement appended to a custom field's name when the field has no value entered."
1438+
},
14351439
"noValuesToCopy": {
14361440
"message": "No values to copy"
14371441
},

libs/vault/src/cipher-view/custom-fields/custom-fields-v2.component.html

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ <h2 bitTypography="h6">{{ "customFields" | i18n }}</h2>
1717
bitInput
1818
[value]="field.value ?? ''"
1919
aria-readonly="true"
20+
[attr.aria-label]="emptyFieldAriaLabel(field)"
2021
vaultAutosizeReadOnlyTextArea
2122
></textarea>
22-
<button
23-
bitIconButton="bwi-clone"
24-
bitSuffix
25-
type="button"
26-
[appCopyClick]="field.value"
27-
showToast
28-
[valueLabel]="field.name"
29-
[label]="'copyCustomField' | i18n: field.name"
30-
data-testid="copy-custom-field"
31-
></button>
23+
@if (field.value) {
24+
<button
25+
bitIconButton="bwi-clone"
26+
bitSuffix
27+
type="button"
28+
[appCopyClick]="field.value"
29+
showToast
30+
[valueLabel]="field.name"
31+
[label]="'copyCustomField' | i18n: field.name"
32+
data-testid="copy-custom-field"
33+
></button>
34+
}
3235
</bit-form-field>
3336
}
3437
@if (field.type === fieldType.Hidden) {
@@ -41,6 +44,7 @@ <h2 bitTypography="h6">{{ "customFields" | i18n }}</h2>
4144
type="password"
4245
[value]="field.value ?? ''"
4346
aria-readonly="true"
47+
[attr.aria-label]="emptyFieldAriaLabel(field)"
4448
class="tw-font-mono"
4549
/>
4650
}
@@ -50,7 +54,7 @@ <h2 bitTypography="h6">{{ "customFields" | i18n }}</h2>
5054
readonly
5155
bitInput
5256
type="password"
53-
[value]="field.value"
57+
[value]="field.value ?? ''"
5458
aria-readonly="true"
5559
class="tw-font-mono"
5660
vaultAutosizeReadOnlyTextArea
@@ -73,7 +77,7 @@ <h2 bitTypography="h6">{{ "customFields" | i18n }}</h2>
7377
(click)="toggleCharacterCount(i)"
7478
></button>
7579
}
76-
@if (canViewPassword) {
80+
@if (canViewPassword && field.value) {
7781
<button
7882
bitSuffix
7983
type="button"
@@ -82,7 +86,7 @@ <h2 bitTypography="h6">{{ "customFields" | i18n }}</h2>
8286
(toggledChange)="toggleHiddenField($event, i)"
8387
></button>
8488
}
85-
@if (canViewPassword) {
89+
@if (canViewPassword && field.value) {
8690
<button
8791
bitIconButton="bwi-clone"
8892
bitSuffix

libs/vault/src/cipher-view/custom-fields/custom-fields-v2.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CipherType, FieldType, LinkedIdType } from "@bitwarden/common/vault/enu
88
import { LinkedMetadata } from "@bitwarden/common/vault/linked-field-option.decorator";
99
import { CardView } from "@bitwarden/common/vault/models/view/card.view";
1010
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
11+
import { FieldView } from "@bitwarden/common/vault/models/view/field.view";
1112
import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view";
1213
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
1314
import {
@@ -83,6 +84,13 @@ export class CustomFieldV2Component implements OnInit, OnChanges {
8384
return this.cipher.viewPassword;
8485
}
8586

87+
emptyFieldAriaLabel(field: FieldView): string | null {
88+
if (field.value) {
89+
return null;
90+
}
91+
return `${field.name}, ${this.i18nService.t("noValueEntered")}`;
92+
}
93+
8694
toggleCharacterCount(index: number) {
8795
const fieldIndex = this.showHiddenValueCountFields.indexOf(index);
8896
if (fieldIndex > -1) {

0 commit comments

Comments
 (0)