From 2fc05735774f0ad1a08be791054dcd9cf1812af6 Mon Sep 17 00:00:00 2001 From: i7slegend Date: Fri, 10 May 2024 17:16:53 +0300 Subject: [PATCH] refactor(unique-id): use composition api to generate component unique id --- components/lib/accordion/Accordion.vue | 16 ++++++------- components/lib/autocomplete/AutoComplete.vue | 16 ++++++------- components/lib/calendar/BaseCalendar.vue | 4 ---- components/lib/calendar/Calendar.vue | 20 ++++++++-------- .../lib/cascadeselect/CascadeSelect.vue | 16 ++++++------- components/lib/chips/Chips.vue | 18 +++++++------- components/lib/contextmenu/ContextMenu.vue | 16 ++++++------- components/lib/datatable/ColumnFilter.vue | 18 +++++++------- components/lib/dialog/Dialog.vue | 18 +++++++------- components/lib/dock/DockSub.vue | 18 +++++++------- components/lib/dropdown/Dropdown.vue | 16 ++++++------- components/lib/fieldset/Fieldset.vue | 16 ++++++------- components/lib/galleria/GalleriaContent.vue | 16 ++++++------- components/lib/listbox/Listbox.vue | 16 ++++++------- components/lib/megamenu/MegaMenu.vue | 16 ++++++------- components/lib/menu/Menu.vue | 18 +++++++------- components/lib/menubar/Menubar.vue | 16 ++++++------- components/lib/multiselect/MultiSelect.vue | 16 ++++++------- components/lib/orderlist/OrderList.vue | 18 +++++++------- components/lib/panel/Panel.vue | 16 ++++++------- components/lib/panelmenu/PanelMenu.vue | 18 +++++++------- components/lib/password/Password.vue | 18 +++++++------- components/lib/picklist/PickList.vue | 16 ++++++------- components/lib/rating/Rating.vue | 18 +++++++------- components/lib/scrollpanel/ScrollPanel.vue | 18 +++++++------- components/lib/speeddial/SpeedDial.vue | 16 ++++++------- components/lib/splitbutton/SplitButton.vue | 18 +++++++------- components/lib/stepper/Stepper.vue | 16 ++++++------- components/lib/tabview/TabView.vue | 16 ++++++------- components/lib/tieredmenu/TieredMenu.vue | 16 ++++++------- components/lib/treeselect/TreeSelect.vue | 16 ++++++------- components/lib/utils/Utils.d.ts | 3 +++ components/lib/utils/Utils.js | 3 ++- components/lib/utils/useUniqueId.js | 24 +++++++++++++++++++ 34 files changed, 271 insertions(+), 269 deletions(-) create mode 100644 components/lib/utils/useUniqueId.js diff --git a/components/lib/accordion/Accordion.vue b/components/lib/accordion/Accordion.vue index 534e9b37f5..453134a4d2 100755 --- a/components/lib/accordion/Accordion.vue +++ b/components/lib/accordion/Accordion.vue @@ -57,7 +57,7 @@ import ChevronDownIcon from 'primevue/icons/chevrondown'; import ChevronRightIcon from 'primevue/icons/chevronright'; import Ripple from 'primevue/ripple'; -import { DomHandler, UniqueComponentId } from 'primevue/utils'; +import { DomHandler, useUniqueId } from 'primevue/utils'; import { mergeProps } from 'vue'; import BaseAccordion from './BaseAccordion.vue'; @@ -66,19 +66,19 @@ export default { extends: BaseAccordion, inheritAttrs: false, emits: ['update:activeIndex', 'tab-open', 'tab-close', 'tab-click'], + setup() { + const { id } = useUniqueId(); + + return { + id + } + }, data() { return { - id: this.$attrs.id, d_activeIndex: this.activeIndex }; }, watch: { - '$attrs.id': { - immediate: true, - handler: function (newValue) { - this.id = newValue || UniqueComponentId(); - } - }, activeIndex(newValue) { this.d_activeIndex = newValue; } diff --git a/components/lib/autocomplete/AutoComplete.vue b/components/lib/autocomplete/AutoComplete.vue index ee5b848a74..635315785a 100755 --- a/components/lib/autocomplete/AutoComplete.vue +++ b/components/lib/autocomplete/AutoComplete.vue @@ -173,7 +173,7 @@ import TimesCircleIcon from 'primevue/icons/timescircle'; import OverlayEventBus from 'primevue/overlayeventbus'; import Portal from 'primevue/portal'; import Ripple from 'primevue/ripple'; -import { ConnectedOverlayScrollHandler, DomHandler, ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primevue/utils'; +import { ConnectedOverlayScrollHandler, DomHandler, ObjectUtils, ZIndexUtils, useUniqueId } from 'primevue/utils'; import VirtualScroller from 'primevue/virtualscroller'; import BaseAutoComplete from './BaseAutoComplete.vue'; @@ -189,9 +189,15 @@ export default { virtualScroller: null, searchTimeout: null, dirty: false, + setup() { + const { id } = useUniqueId(); + + return { + id + } + }, data() { return { - id: this.$attrs.id, clicked: false, focused: false, focusedOptionIndex: -1, @@ -201,12 +207,6 @@ export default { }; }, watch: { - '$attrs.id': { - immediate: true, - handler: function (newValue) { - this.id = newValue || UniqueComponentId(); - } - }, suggestions() { if (this.searching) { this.show(); diff --git a/components/lib/calendar/BaseCalendar.vue b/components/lib/calendar/BaseCalendar.vue index 6b0e7940f9..01dd216862 100644 --- a/components/lib/calendar/BaseCalendar.vue +++ b/components/lib/calendar/BaseCalendar.vue @@ -196,10 +196,6 @@ export default { type: String, default: null }, - id: { - type: String, - default: null - }, inputId: { type: String, default: null diff --git a/components/lib/calendar/Calendar.vue b/components/lib/calendar/Calendar.vue index 82dabdba3c..353ea2417a 100755 --- a/components/lib/calendar/Calendar.vue +++ b/components/lib/calendar/Calendar.vue @@ -1,5 +1,5 @@