File tree 2 files changed +24
-13
lines changed
addon/components/hds/dropdown/list-item
tests/dummy/app/templates/components
2 files changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { tracked } from '@glimmer/tracking';
4
4
import { action } from '@ember/object' ;
5
5
6
6
export default class HdsDropdownListItemCopyItemComponent extends Component {
7
- @tracked isSuccess = this . args . isSuccess ?? false ;
7
+ @tracked isSuccess = false ;
8
8
9
9
/**
10
10
* @param text
@@ -37,12 +37,19 @@ export default class HdsDropdownListItemCopyItemComponent extends Component {
37
37
}
38
38
39
39
@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 ) {
45
46
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 ) ;
46
53
}
47
54
}
48
55
}
Original file line number Diff line number Diff line change 153
153
</dd >
154
154
</dl >
155
155
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 >
159
166
160
167
<h4 class =" dummy-h4" >ListItem::Description</h4 >
161
168
<p class =" dummy-paragraph" id =" component-api-listitem-description" >Here is the API for the "description" list item
483
490
<Hds::Link::Standalone @text="Watch tutorial video" @icon="film" href="/" />
484
491
</dd.Generic>
485
492
<dd.CopyItem @text="https://api.cloud.hashicorp.com" @copyItemTitle="Endpoint URL" />
486
- <dd.CopyLabel />
487
- <dd.CopyItem @text="91ee1e8ef65b337f0e70d793f456c71d" @text="HMAC Key" />
488
- <dd.Separator />
489
- <dd.Interactive @route="components.dropdown" @text="Docs: Import usage" @icon="docs-link" />
493
+ <dd.CopyItem @text="91ee1e8ef65b337f0e70d793f456c71d" @copyItemTitle="HMAC Key" />
490
494
</Hds::Dropdown>
491
495
'
492
496
/>
You can’t perform that action at this time.
0 commit comments