File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
test/runtime-browser/custom-elements-samples/reflect-attributes-add-remove Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: take custom attribute name into account when reflecting property
Original file line number Diff line number Diff line change @@ -283,7 +283,7 @@ if (typeof HTMLElement === 'function') {
283
283
'toAttribute'
284
284
) ;
285
285
if ( attribute_value == null ) {
286
- this . removeAttribute ( key ) ;
286
+ this . removeAttribute ( this . $$p_d [ key ] . attribute || key ) ;
287
287
} else {
288
288
this . setAttribute ( this . $$p_d [ key ] . attribute || key , attribute_value ) ;
289
289
}
Original file line number Diff line number Diff line change
1
+ <svelte:options
2
+ customElement ={{
3
+ tag : ' custom-element' ,
4
+ props : {
5
+ expanded : { reflect : true , type : ' Boolean' , attribute : ' aria-expanded' }
6
+ }
7
+ }}
8
+ />
9
+
10
+ <script >
11
+ export let expanded = false ;
12
+ </script >
13
+
14
+ <div >
15
+ <button on:click ={() => (expanded = ! expanded )}>Toggle</button >
16
+ <div class:hidden ={! expanded }>Hidden Text</div >
17
+ </div >
18
+
19
+ <style >
20
+ .hidden {
21
+ display : none ;
22
+ }
23
+ </style >
Original file line number Diff line number Diff line change
1
+ import * as assert from 'assert.js' ;
2
+ import { tick } from 'svelte' ;
3
+ import './main.svelte' ;
4
+
5
+ export default async function ( target ) {
6
+ const element = document . createElement ( 'custom-element' ) ;
7
+ target . appendChild ( element ) ;
8
+ await tick ( ) ;
9
+
10
+ const el = target . querySelector ( 'custom-element' ) ;
11
+ el . shadowRoot . querySelector ( 'button' ) . click ( ) ;
12
+ await tick ( ) ;
13
+
14
+ assert . equal ( el . getAttribute ( 'aria-expanded' ) , '' ) ;
15
+ el . shadowRoot . querySelector ( 'button' ) . click ( ) ;
16
+ await tick ( ) ;
17
+
18
+ assert . equal ( el . getAttribute ( 'aria-expanded' ) , null ) ;
19
+ }
You can’t perform that action at this time.
0 commit comments