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

UI: Fix copy button not working for non-string masked values #25269

Merged
merged 2 commits into from
Feb 7, 2024
Merged
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: 3 additions & 0 deletions changelog/25269.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix copy button not working on masked input when value is not a string
```
4 changes: 2 additions & 2 deletions ui/lib/core/addon/components/masked-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<Hds::Copy::Button
@text="Copy"
@isIconOnly={{true}}
@textToCopy={{@value}}
@textToCopy={{this.copyValue}}
class="transparent has-padding-xxs"
data-test-copy-button={{or @value true}}
data-test-copy-button={{or this.copyValue true}}
/>
{{/if}}
{{#if @allowDownload}}
Expand Down
7 changes: 7 additions & 0 deletions ui/lib/core/addon/components/masked-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ export default class MaskedInputComponent extends Component {
@action toggleStringifyDownload(event) {
this.stringifyDownload = event.target.checked;
}

get copyValue() {
// Value must be a string to be copied
if (typeof this.args.value === 'string') return this.args.value;
if (typeof this.args.value === 'object') return JSON.stringify(this.args.value);
return this.args.value.toString();
}
}
9 changes: 6 additions & 3 deletions ui/tests/integration/components/masked-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ module('Integration | Component | masked input', function (hooks) {
});

test('it renders a copy button when allowCopy is true', async function (assert) {
await render(hbs`<MaskedInput @allowCopy={{true}} />`);
this.set('value', { some: 'object' });
await render(hbs`<MaskedInput @allowCopy={{true}} @value={{this.value}} />`);
assert.ok(component.copyButtonIsPresent);
await click('[data-test-copy-icon]');
assert
.dom('flight-icon-clipboard-checked')
.exists('clicking copy icon copies value to clipboard', 'copy is successful when value is an object');
});

test('it renders a download button when allowDownload is true', async function (assert) {
Expand All @@ -56,8 +61,6 @@ module('Integration | Component | masked input', function (hooks) {

await click('[data-test-download-icon]');
assert.ok(component.downloadButtonIsPresent, 'clicking download icon opens modal with download button');

assert;
});

test('it shortens all outputs when displayOnly and masked', async function (assert) {
Expand Down
Loading