@@ -204,7 +204,13 @@ export class PfButton extends LitElement {
204204 /** Icon set for the `icon` property */
205205 @property ( { attribute : 'icon-set' } ) iconSet ?: string ;
206206
207- #internals = InternalsController . of ( this , { role : 'button' } ) ;
207+ /** Store the URL Link */
208+ @property ( { reflect : true } ) href ?: string ;
209+
210+ /** Redirecting the URL Link to new Tab */
211+ @property ( { reflect : true } ) target ?: string ;
212+
213+ #internals = InternalsController . of ( this , { role : this . variant === 'link' ? 'none' : 'button' } ) ;
208214
209215 #slots = new SlotController ( this , 'icon' , null ) ;
210216
@@ -216,12 +222,19 @@ export class PfButton extends LitElement {
216222 super . connectedCallback ( ) ;
217223 this . addEventListener ( 'click' , this . #onClick) ;
218224 this . addEventListener ( 'keydown' , this . #onKeydown) ;
219- this . tabIndex = 0 ;
220225 }
221226
222227 protected override willUpdate ( ) : void {
223228 this . #internals. ariaLabel = this . label || null ;
224229 this . #internals. ariaDisabled = String ( ! ! this . disabled ) ;
230+ const isLink = this . variant === 'link' && this . href ;
231+ if ( isLink ) {
232+ this . removeAttribute ( 'tabindex' ) ;
233+ this . #internals. role = 'none' ;
234+ } else {
235+ this . tabIndex = 0 ;
236+ this . #internals. role = 'button' ;
237+ }
225238 }
226239
227240 async formDisabledCallback ( ) : Promise < void > {
@@ -231,9 +244,46 @@ export class PfButton extends LitElement {
231244
232245 override render ( ) : TemplateResult < 1 > {
233246 const hasIcon = ! ! this . icon || ! ! this . loading || this . #slots. hasSlotted ( 'icon' ) ;
234- const { warning, variant, danger, loading, plain, inline, block, size } = this ;
247+ const { warning, variant, danger, loading, plain, inline, block, size, href, target } = this ;
248+
235249 const disabled = this . #disabled;
236- return html `
250+
251+ const content = html `
252+ < slot id ="icon "
253+ part ="icon "
254+ name ="icon "
255+ ?hidden ="${ ! hasIcon } ">
256+ < pf-icon role ="presentation "
257+ icon ="${ ifDefined ( this . icon ) } "
258+ set ="${ ifDefined ( this . iconSet ) } "
259+ ?hidden ="${ ! this . icon || this . loading } "> </ pf-icon >
260+ < pf-spinner size ="md "
261+ ?hidden ="${ ! this . loading } "
262+ aria-label ="${ this . getAttribute ( 'loading-label' ) ?? 'loading' } "> </ pf-spinner >
263+ </ slot >
264+ < slot id ="text "> </ slot >
265+ ` ;
266+
267+ if ( variant === 'link' && href ) {
268+ return html `
269+ < a id ="button "
270+ href ="${ href } "
271+ target ="${ ifDefined ( target ) } "
272+ class ="${ classMap ( {
273+ [ variant ] : true ,
274+ [ size ?? '' ] : ! ! size ,
275+ anchor : true ,
276+ inline,
277+ block,
278+ danger,
279+ disabled,
280+ hasIcon,
281+ loading,
282+ plain,
283+ warning,
284+ } ) } "> ${ content } </ a > `;
285+ } else {
286+ return html `
237287 < div id ="button "
238288 class ="${ classMap ( {
239289 [ variant ] : true ,
@@ -246,22 +296,8 @@ export class PfButton extends LitElement {
246296 loading,
247297 plain,
248298 warning,
249- } ) } ">
250- < slot id ="icon "
251- part ="icon "
252- name ="icon "
253- ?hidden ="${ ! hasIcon } ">
254- < pf-icon role ="presentation "
255- icon ="${ ifDefined ( this . icon ) } "
256- set ="${ ifDefined ( this . iconSet ) } "
257- ?hidden ="${ ! this . icon || this . loading } "> </ pf-icon >
258- < pf-spinner size ="md "
259- ?hidden ="${ ! this . loading } "
260- aria-label ="${ this . getAttribute ( 'loading-label' ) ?? 'loading' } "> </ pf-spinner >
261- </ slot >
262- < slot id ="text "> </ slot >
263- </ div >
264- ` ;
299+ } ) } "> ${ content } </ div > `;
300+ }
265301 }
266302
267303 #onClick( ) {
0 commit comments