@@ -3,7 +3,9 @@ import { customElement } from 'lit/decorators/custom-element.js';
33import { queryAssignedNodes } from 'lit/decorators/query-assigned-nodes.js' ;
44import { property } from 'lit/decorators/property.js' ;
55import { classMap } from 'lit/directives/class-map.js' ;
6+
67import { InternalsController } from '@patternfly/pfe-core/controllers/internals-controller.js' ;
8+
79import { observes } from '@patternfly/pfe-core/decorators/observes.js' ;
810import styles from './pf-search-input-option.css' ;
911
@@ -15,71 +17,77 @@ import styles from './pf-search-input-option.css';
1517export class PfSearchInputOption extends LitElement {
1618 static readonly styles : CSSStyleSheet [ ] = [ styles ] ;
1719
18- /** form value for this option */
19- @property ( { reflect : true } )
20- get value ( ) {
21- return ( this . #value ?? this . textContent ?? '' ) . trim ( ) ;
22- }
23-
24- set value ( v : string ) {
25- this . #value = v ;
26- }
27-
28- /** whether option is selected */
29- @property ( { type : Boolean , reflect : true } ) selected = false ;
30-
31- /** whether option is active descendant */
32- @property ( { type : Boolean , reflect : true } ) active = false ;
33-
34- @queryAssignedNodes ( { slot : '' , flatten : true } )
35- private _slottedText ! : Node [ ] ;
36-
37- /**
38- * this option's position relative to the other options
39- */
40- set posInSet ( posInSet : number | null ) {
41- this . #internals. ariaPosInSet = `${ Math . max ( 0 , posInSet ?? 0 ) } ` ;
42- }
43-
44- get posInSet ( ) {
45- const parsed = parseInt ( this . #internals. ariaPosInSet ?? '0' ) ;
46- return Number . isNaN ( parsed ) ? null : parsed ;
47- }
48-
49- /**
50- * total number of options
51- */
52- set setSize ( setSize : number | null ) {
53- this . #internals. ariaSetSize = `${ Math . max ( 0 , setSize ?? 0 ) } ` ;
54- }
55-
56- get setSize ( ) {
57- try {
58- const int = parseInt ( this . #internals. ariaSetSize ?? '0' ) ;
59- if ( Number . isNaN ( int ) ) {
60- return 0 ;
61- } else {
62- return int ;
63- }
64- } catch {
20+ /** whether option is disabled */
21+ @property ( { type : Boolean , reflect : true } ) disabled = false ;
22+
23+ /** form value for this option */
24+ @property ( { reflect : true } )
25+ get value ( ) {
26+ return ( this . #value ?? this . textContent ?? '' ) . trim ( ) ;
27+ }
28+
29+ set value ( v : string ) {
30+ this . #value = v ;
31+ }
32+
33+ /** whether option is selected */
34+ @property ( { type : Boolean , reflect : true } ) selected = false ;
35+
36+ /** whether option is active descendant */
37+ @property ( { type : Boolean , reflect : true } ) active = false ;
38+
39+ /** Optional option description; overridden by description slot. */
40+ @property ( ) description = '' ;
41+
42+ @queryAssignedNodes ( { slot : '' , flatten : true } )
43+ private _slottedText ! : Node [ ] ;
44+
45+ /**
46+ * this option's position relative to the other options
47+ */
48+ set posInSet ( posInSet : number | null ) {
49+ this . #internals. ariaPosInSet = `${ Math . max ( 0 , posInSet ?? 0 ) } ` ;
50+ }
51+
52+ get posInSet ( ) {
53+ const parsed = parseInt ( this . #internals. ariaPosInSet ?? '0' ) ;
54+ return Number . isNaN ( parsed ) ? null : parsed ;
55+ }
56+
57+ /**
58+ * total number of options
59+ */
60+ set setSize ( setSize : number | null ) {
61+ this . #internals. ariaSetSize = `${ Math . max ( 0 , setSize ?? 0 ) } ` ;
62+ }
63+
64+ get setSize ( ) {
65+ try {
66+ const int = parseInt ( this . #internals. ariaSetSize ?? '0' ) ;
67+ if ( Number . isNaN ( int ) ) {
6568 return 0 ;
69+ } else {
70+ return int ;
6671 }
72+ } catch {
73+ return 0 ;
6774 }
68-
69- #value?: string ;
70-
71- #internals = InternalsController . of ( this , { role : 'option' } ) ;
72-
75+ }
76+
77+ #value?: string ;
78+
79+ #internals = InternalsController . of ( this , { role : 'option' } ) ;
7380
7481 render ( ) : TemplateResult < 1 > {
75- const { active, selected } = this ;
82+ const { disabled , active, selected } = this ;
7683 return html `
77- < div id ="outer " class ="${ classMap ( { active, selected } ) } ">
84+ < div id ="outer " class ="${ classMap ( { active, disabled , selected } ) } ">
7885 < input type ="checkbox "
7986 inert
8087 role ="presentation "
8188 tabindex ="-1 "
82- ?checked ="${ this . selected } ">
89+ ?checked ="${ this . selected } "
90+ ?disabled ="${ this . disabled } ">
8391 < slot name ="icon "> </ slot >
8492 < span >
8593 < slot name ="create "> </ slot >
@@ -91,6 +99,7 @@ export class PfSearchInputOption extends LitElement {
9199 aria-hidden ="true ">
92100 < path d ="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z "> </ path >
93101 </ svg >
102+ < slot id ="description " name ="description "> ${ this . description ?? '' } </ slot >
94103 </ div >
95104 ` ;
96105 }
@@ -100,6 +109,11 @@ export class PfSearchInputOption extends LitElement {
100109 this . #internals. ariaSelected = String ( ! ! this . selected ) ;
101110 }
102111
112+ @observes ( 'disabled' )
113+ private disabledChanged ( ) {
114+ this . #internals. ariaDisabled = String ( ! ! this . disabled ) ;
115+ }
116+
103117 /**
104118 * text content within option (used for filtering)
105119 */
0 commit comments