11<script >
22import CompactInput from ' @shell/mixins/compact-input' ;
3- import LabeledFormElement from ' @shell/mixins/labeled-form-element' ;
43import { get } from ' @shell/utils/object' ;
54import { LabeledTooltip } from ' @components/LabeledTooltip' ;
65import VueSelectOverrides from ' @shell/mixins/vue-select-overrides' ;
76import { calculatePosition } from ' @shell/utils/select' ;
87import { generateRandomAlphaString } from ' @shell/utils/string' ;
9- import LabeledSelectPagination from ' @shell/components/form/labeled-select-utils/labeled-select-pagination ' ;
8+ import { useLabeledSelectPagination , labeledSelectPaginationProps } from ' @shell/components/form/labeled-select-utils/useLabeledSelectPagination ' ;
109import { LABEL_SELECT_NOT_OPTION_KINDS } from ' @shell/types/components/labeledSelect' ;
1110import { mapGetters } from ' vuex' ;
1211import { _VIEW } from ' @shell/config/query-params' ;
1312import { useClickOutside } from ' @shell/composables/useClickOutside' ;
13+ import { useLabeledFormElement , labeledFormElementProps } from ' @shell/composables/useLabeledFormElement' ;
14+ import { useLabeledSelect } from ' @shell/composables/useLabeledSelect' ;
1415import { ref } from ' vue' ;
1516
1617export default {
@@ -21,14 +22,18 @@ export default {
2122 components: { LabeledTooltip },
2223 mixins: [
2324 CompactInput,
24- LabeledFormElement,
2525 VueSelectOverrides,
26- LabeledSelectPagination
2726 ],
2827
29- emits: [' on-open' , ' on-close' , ' selecting' , ' deselecting' , ' search' , ' update:validation' , ' update:value' ],
28+ emits: [' on-open' , ' on-close' , ' on-focus ' , ' on-blur ' , ' selecting' , ' deselecting' , ' search' , ' update:validation' , ' update:value' ],
3029
3130 props: {
31+ ... labeledFormElementProps,
32+ ... labeledSelectPaginationProps,
33+ value: {
34+ default: null ,
35+ type: [String , Object , Number , Array , Boolean ]
36+ },
3237 appendToBody: {
3338 default: true ,
3439 type: Boolean ,
@@ -37,14 +42,6 @@ export default {
3742 default: false ,
3843 type: Boolean
3944 },
40- disabled: {
41- default: false ,
42- type: Boolean
43- },
44- required: {
45- default: false ,
46- type: Boolean
47- },
4845 hoverTooltip: {
4946 default: true ,
5047 type: Boolean
@@ -99,14 +96,18 @@ export default {
9996 default: null ,
10097 type: [String , Object ]
10198 },
102- value: {
103- default: null ,
104- type: [String , Object , Number , Array , Boolean ]
105- },
10699 options: {
107100 type: Array ,
108101 default : () => ([])
109102 },
103+ searchable: {
104+ default: false ,
105+ type: Boolean
106+ },
107+ filterable: {
108+ default: true ,
109+ type: Boolean
110+ },
110111 closeOnSelect: {
111112 type: Boolean ,
112113 default: true
@@ -117,15 +118,75 @@ export default {
117118 }
118119 },
119120
120- setup () {
121+ setup (props , { emit } ) {
121122 const select = ref (null );
122123 const isOpen = ref (false );
123124
124125 useClickOutside (select, () => {
125126 isOpen .value = false ;
126127 });
127128
128- return { isOpen, select };
129+ const {
130+ raised ,
131+ focused ,
132+ blurred ,
133+ empty ,
134+ isView ,
135+ onFocusLabeled ,
136+ onBlurLabeled ,
137+ isDisabled ,
138+ validationMessage ,
139+ requiredField
140+ } = useLabeledFormElement (props, emit);
141+
142+ const {
143+ canPaginate ,
144+ canLoadMore ,
145+ optionCounts ,
146+ _options ,
147+ pages ,
148+ totalResults ,
149+ paginating ,
150+ loadMore ,
151+ setPaginationFilter ,
152+ } = useLabeledSelectPagination (props);
153+
154+ const {
155+ isSearchable ,
156+ isFilterable ,
157+ resizeHandler: resizeHandlerFn
158+ } = useLabeledSelect (props, canPaginate);
159+
160+ const resizeHandler = () => {
161+ resizeHandlerFn (select);
162+ };
163+
164+ return {
165+ isOpen,
166+ select,
167+ raised,
168+ focused,
169+ blurred,
170+ empty,
171+ isView,
172+ onFocusLabeled,
173+ onBlurLabeled,
174+ isDisabled,
175+ validationMessage,
176+ requiredField,
177+ isSearchable,
178+ isFilterable,
179+ resizeHandler,
180+ canPaginate,
181+ canLoadMore,
182+ optionCounts,
183+ _options,
184+ pages,
185+ totalResults,
186+ paginating,
187+ loadMore,
188+ setPaginationFilter,
189+ };
129190 },
130191
131192 data () {
@@ -148,11 +209,6 @@ export default {
148209 return this .canPaginate ? !! this ._options .find ((o ) => o .kind === ' group' && !! o .icon ) : false ;
149210 },
150211
151- _options () {
152- // If we're paginated show the page as provided by `paginate`. See label-select-pagination mixin
153- return this .canPaginate ? this .page : this .options ;
154- },
155-
156212 filteredAttrs () {
157213 const {
158214 class: _class ,
@@ -207,11 +263,13 @@ export default {
207263 },
208264
209265 onFocus () {
266+ this .$emit (' on-focus' );
210267 this .selectedVisibility = ' hidden' ;
211268 this .onFocusLabeled ();
212269 },
213270
214271 onBlur () {
272+ this .$emit (' on-blur' );
215273 this .selectedVisibility = ' visible' ;
216274 this .onBlurLabeled ();
217275 },
0 commit comments