File tree Expand file tree Collapse file tree 1 file changed +29
-7
lines changed Expand file tree Collapse file tree 1 file changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -65,13 +65,35 @@ export class TPMultiSelectPillsElement extends HTMLElement {
6565 return ;
6666 }
6767
68- const newPill : HTMLElement = document . createElement ( 'tp-multi-select-pill' ) ;
69- newPill . setAttribute ( 'value' , pillValue ) ;
70- newPill . innerHTML = `
71- <span>${ multiSelectOption . getAttribute ( 'label' ) ?? '' } </span>
72- <button type="button">x</button>
73- ` ;
74- this . appendChild ( newPill ) ;
68+ this . appendChild ( this . createPill ( pillValue , multiSelectOption . getAttribute ( 'label' ) ?? '' ) ) ;
7569 } ) ;
7670 }
71+
72+ /**
73+ * Create a new pill.
74+ *
75+ * @param {string } value Pill value.
76+ * @param {string } label Pill label.
77+ *
78+ * @return {TPMultiSelectPillElement } New pill.
79+ */
80+ createPill ( value : string , label : string ) : TPMultiSelectPillElement {
81+ const newPill = document . createElement ( 'tp-multi-select-pill' ) as TPMultiSelectPillElement ;
82+ newPill . setAttribute ( 'value' , value ) ;
83+
84+ const pillLabel : HTMLElement = document . createElement ( 'span' ) ;
85+ pillLabel . textContent = label ;
86+
87+ const pillCloseButton : HTMLElement = document . createElement ( 'button' ) ;
88+ pillCloseButton . setAttribute ( 'type' , 'button' ) ;
89+ pillCloseButton . textContent = 'x' ;
90+ pillCloseButton . addEventListener ( 'click' , ( ) => {
91+ newPill . removePill ( ) ;
92+ } ) ;
93+
94+ newPill . appendChild ( pillLabel ) ;
95+ newPill . appendChild ( pillCloseButton ) ;
96+
97+ return newPill ;
98+ }
7799}
You can’t perform that action at this time.
0 commit comments