Skip to content

Commit fb78f98

Browse files
authored
Merge pull request #274 from hashicorp/melsumner/dropdown-bugfix
dropdown component bugfixes
2 parents bcded03 + 8aa360f commit fb78f98

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

packages/components/addon/components/hds/dropdown/list-item/copy-item.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { tracked } from '@glimmer/tracking';
44
import { action } from '@ember/object';
55

66
export default class HdsDropdownListItemCopyItemComponent extends Component {
7-
@tracked isSuccess = this.args.isSuccess ?? false;
7+
@tracked isSuccess = false;
88

99
/**
1010
* @param text
@@ -37,12 +37,19 @@ export default class HdsDropdownListItemCopyItemComponent extends Component {
3737
}
3838

3939
@action
40-
copyCode() {
41-
navigator.clipboard.writeText(this.args.text);
42-
// this if statement resolves to [object Promise] so maybe some improvements
43-
// could be made here
44-
if (navigator.clipboard.readText()) {
40+
async copyCode() {
41+
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
42+
await navigator.clipboard.writeText(this.args.text);
43+
const result = await navigator.clipboard.readText();
44+
45+
if (result === this.args.text) {
4546
this.isSuccess = true;
47+
// console.log(`result is ${result}`);
48+
49+
// make it fade back to the default state
50+
setTimeout(() => {
51+
this.isSuccess = false;
52+
}, 1000);
4653
}
4754
}
4855
}

packages/components/tests/dummy/app/templates/components/dropdown.hbs

+11-7
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,16 @@
153153
</dd>
154154
</dl>
155155

156-
<h4 class="dummy-h4">ListItem::CopyItem</h4>
157-
{{! TODO: add props here if we decide to use the current version }}
158-
<p class="dummy-paragraph">[WIP]</p>
156+
<h4 class="dummy-h4" id="api-listitem-copyitem">ListItem::CopyItem</h4>
157+
<dl class="dummy-component-props" aria-labelledby="api-listitem-copyitem">
158+
<dt>copyItemTitle <code>string</code></dt>
159+
<dd>Optional. Provides a contextual title for the text to be copied.</dd>
160+
<dt>text <code>string</code></dt>
161+
<dd>
162+
<p>The text to be copied.</p>
163+
<p><em>If no text value is defined an error will be thrown.</em></p>
164+
</dd>
165+
</dl>
159166

160167
<h4 class="dummy-h4">ListItem::Description</h4>
161168
<p class="dummy-paragraph" id="component-api-listitem-description">Here is the API for the "description" list item
@@ -483,10 +490,7 @@
483490
&lt;Hds::Link::Standalone @text="Watch tutorial video" @icon="film" href="/" /&gt;
484491
&lt;/dd.Generic&gt;
485492
&lt;dd.CopyItem @text="https://api.cloud.hashicorp.com" @copyItemTitle="Endpoint URL" /&gt;
486-
&lt;dd.CopyLabel /&gt;
487-
&lt;dd.CopyItem @text="91ee1e8ef65b337f0e70d793f456c71d" @text="HMAC Key" /&gt;
488-
&lt;dd.Separator /&gt;
489-
&lt;dd.Interactive @route="components.dropdown" @text="Docs: Import usage" @icon="docs-link" /&gt;
493+
&lt;dd.CopyItem @text="91ee1e8ef65b337f0e70d793f456c71d" @copyItemTitle="HMAC Key" /&gt;
490494
&lt;/Hds::Dropdown&gt;
491495
'
492496
/>

0 commit comments

Comments
 (0)