@pega/cosmos-react-core 3.0.0-dev.16.0 → 3.0.0-dev.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppShell/AppHeader.d.ts.map +1 -1
- package/lib/components/AppShell/AppHeader.js +4 -6
- package/lib/components/AppShell/AppHeader.js.map +1 -1
- package/lib/components/AppShell/AppHeader.styles.d.ts +16 -0
- package/lib/components/AppShell/AppHeader.styles.d.ts.map +1 -0
- package/lib/components/AppShell/AppHeader.styles.js +155 -0
- package/lib/components/AppShell/AppHeader.styles.js.map +1 -0
- package/lib/components/AppShell/AppShell.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.js +44 -157
- package/lib/components/AppShell/AppShell.js.map +1 -1
- package/lib/components/AppShell/AppShell.styles.d.ts +7 -51
- package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.styles.js +44 -535
- package/lib/components/AppShell/AppShell.styles.js.map +1 -1
- package/lib/components/AppShell/AppShell.types.d.ts +16 -5
- package/lib/components/AppShell/AppShell.types.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.types.js.map +1 -1
- package/lib/components/AppShell/AppShellContext.d.ts +2 -0
- package/lib/components/AppShell/AppShellContext.d.ts.map +1 -1
- package/lib/components/AppShell/AppShellContext.js +2 -0
- package/lib/components/AppShell/AppShellContext.js.map +1 -1
- package/lib/components/AppShell/AppShellList.js +3 -1
- package/lib/components/AppShell/AppShellList.js.map +1 -1
- package/lib/components/AppShell/AppShellList.styles.d.ts +19 -0
- package/lib/components/AppShell/AppShellList.styles.d.ts.map +1 -0
- package/lib/components/AppShell/AppShellList.styles.js +141 -0
- package/lib/components/AppShell/AppShellList.styles.js.map +1 -0
- package/lib/components/AppShell/AppShellSearch.d.ts +10 -0
- package/lib/components/AppShell/AppShellSearch.d.ts.map +1 -0
- package/lib/components/AppShell/AppShellSearch.js +32 -0
- package/lib/components/AppShell/AppShellSearch.js.map +1 -0
- package/lib/components/AppShell/AppShellSearch.styles.d.ts +8 -0
- package/lib/components/AppShell/AppShellSearch.styles.d.ts.map +1 -0
- package/lib/components/AppShell/AppShellSearch.styles.js +190 -0
- package/lib/components/AppShell/AppShellSearch.styles.js.map +1 -0
- package/lib/components/AppShell/Drawer.js +2 -2
- package/lib/components/AppShell/Drawer.js.map +1 -1
- package/lib/components/AppShell/Drawer.styles.d.ts +15 -0
- package/lib/components/AppShell/Drawer.styles.d.ts.map +1 -0
- package/lib/components/AppShell/Drawer.styles.js +153 -0
- package/lib/components/AppShell/Drawer.styles.js.map +1 -0
- package/lib/components/AppShell/NavigationList.d.ts +5 -0
- package/lib/components/AppShell/NavigationList.d.ts.map +1 -0
- package/lib/components/AppShell/NavigationList.js +123 -0
- package/lib/components/AppShell/NavigationList.js.map +1 -0
- package/lib/components/AppShell/NavigationListItemWrapper.d.ts +5 -0
- package/lib/components/AppShell/NavigationListItemWrapper.d.ts.map +1 -0
- package/lib/components/AppShell/NavigationListItemWrapper.js +109 -0
- package/lib/components/AppShell/NavigationListItemWrapper.js.map +1 -0
- package/lib/components/AppShell/Operator.js +4 -4
- package/lib/components/AppShell/Operator.js.map +1 -1
- package/lib/components/Badges/Keyboard.d.ts.map +1 -1
- package/lib/components/Badges/Keyboard.js +2 -0
- package/lib/components/Badges/Keyboard.js.map +1 -1
- package/lib/components/Badges/Selection.d.ts +1 -1
- package/lib/components/Badges/Selection.d.ts.map +1 -1
- package/lib/components/Badges/Selection.js +4 -2
- package/lib/components/Badges/Selection.js.map +1 -1
- package/lib/components/Banner/Banner.d.ts.map +1 -1
- package/lib/components/Banner/Banner.js +2 -0
- package/lib/components/Banner/Banner.js.map +1 -1
- package/lib/components/Breadcrumbs/Breadcrumbs.d.ts +2 -1
- package/lib/components/Breadcrumbs/Breadcrumbs.d.ts.map +1 -1
- package/lib/components/Breadcrumbs/Breadcrumbs.js +37 -10
- package/lib/components/Breadcrumbs/Breadcrumbs.js.map +1 -1
- package/lib/components/ComboBox/ComboBox.d.ts.map +1 -1
- package/lib/components/ComboBox/ComboBox.js +56 -15
- package/lib/components/ComboBox/ComboBox.js.map +1 -1
- package/lib/components/ComboBox/ComboBox.styles.d.ts +3 -1
- package/lib/components/ComboBox/ComboBox.styles.d.ts.map +1 -1
- package/lib/components/ComboBox/ComboBox.types.d.ts +5 -1
- package/lib/components/ComboBox/ComboBox.types.d.ts.map +1 -1
- package/lib/components/ComboBox/ComboBox.types.js.map +1 -1
- package/lib/components/ComboBox/ComboBoxInput.d.ts +7 -0
- package/lib/components/ComboBox/ComboBoxInput.d.ts.map +1 -1
- package/lib/components/ComboBox/ComboBoxInput.js +5 -2
- package/lib/components/ComboBox/ComboBoxInput.js.map +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.d.ts.map +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js +113 -37
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js.map +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.types.d.ts +10 -0
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.types.d.ts.map +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.types.js.map +1 -1
- package/lib/components/ComboBox/SingleSelectInput/SingleSelectInput.d.ts.map +1 -1
- package/lib/components/ComboBox/SingleSelectInput/SingleSelectInput.js +2 -2
- package/lib/components/ComboBox/SingleSelectInput/SingleSelectInput.js.map +1 -1
- package/lib/components/ComboBox/SingleSelectInput/SingleSelectInput.types.d.ts +2 -0
- package/lib/components/ComboBox/SingleSelectInput/SingleSelectInput.types.d.ts.map +1 -1
- package/lib/components/ComboBox/SingleSelectInput/SingleSelectInput.types.js.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.d.ts.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.js +2 -2
- package/lib/components/CompositeInput/CompositeInput.js.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.styles.d.ts.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.styles.js +19 -17
- package/lib/components/CompositeInput/CompositeInput.styles.js.map +1 -1
- package/lib/components/Currency/CurrencyInput.d.ts.map +1 -1
- package/lib/components/Currency/CurrencyInput.js +17 -4
- package/lib/components/Currency/CurrencyInput.js.map +1 -1
- package/lib/components/Currency/utils.d.ts.map +1 -1
- package/lib/components/Currency/utils.js +3 -2
- package/lib/components/Currency/utils.js.map +1 -1
- package/lib/components/DateTime/DateTime.types.d.ts +2 -0
- package/lib/components/DateTime/DateTime.types.d.ts.map +1 -1
- package/lib/components/DateTime/DateTime.types.js.map +1 -1
- package/lib/components/DateTime/Input/DateInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateInput.js +12 -3
- package/lib/components/DateTime/Input/DateInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.js +12 -3
- package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.js +6 -12
- package/lib/components/DateTime/Picker/Calendar.js.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.styles.d.ts +2 -4
- package/lib/components/DateTime/Picker/Calendar.styles.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.styles.js +13 -55
- package/lib/components/DateTime/Picker/Calendar.styles.js.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.js +2 -1
- package/lib/components/DateTime/Picker/DatePicker.js.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.styles.d.ts +3 -0
- package/lib/components/DateTime/Picker/DatePicker.styles.d.ts.map +1 -0
- package/lib/components/DateTime/Picker/DatePicker.styles.js +39 -0
- package/lib/components/DateTime/Picker/DatePicker.styles.js.map +1 -0
- package/lib/components/DateTime/Picker/DateRangePicker.js +1 -1
- package/lib/components/DateTime/Picker/DateRangePicker.js.map +1 -1
- package/lib/components/DateTime/Picker/TimePicker.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/TimePicker.js +10 -5
- package/lib/components/DateTime/Picker/TimePicker.js.map +1 -1
- package/lib/components/DateTime/index.d.ts +2 -0
- package/lib/components/DateTime/index.d.ts.map +1 -1
- package/lib/components/DateTime/index.js +2 -0
- package/lib/components/DateTime/index.js.map +1 -1
- package/lib/components/Dialog/Dialog.d.ts.map +1 -1
- package/lib/components/Dialog/Dialog.js +3 -2
- package/lib/components/Dialog/Dialog.js.map +1 -1
- package/lib/components/ExpandCollapse/ExpandCollapse.d.ts.map +1 -1
- package/lib/components/ExpandCollapse/ExpandCollapse.js +1 -1
- package/lib/components/ExpandCollapse/ExpandCollapse.js.map +1 -1
- package/lib/components/FieldGroup/FieldGroup.d.ts.map +1 -1
- package/lib/components/FieldGroup/FieldGroup.js +28 -26
- package/lib/components/FieldGroup/FieldGroup.js.map +1 -1
- package/lib/components/FormControl/FormControl.d.ts +6 -2
- package/lib/components/FormControl/FormControl.d.ts.map +1 -1
- package/lib/components/FormControl/FormControl.js +60 -35
- package/lib/components/FormControl/FormControl.js.map +1 -1
- package/lib/components/FormField/FormField.d.ts.map +1 -1
- package/lib/components/FormField/FormField.js +65 -5
- package/lib/components/FormField/FormField.js.map +1 -1
- package/lib/components/Input/Input.d.ts.map +1 -1
- package/lib/components/Input/Input.js +13 -2
- package/lib/components/Input/Input.js.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.d.ts.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.js +64 -9
- package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.types.d.ts +2 -0
- package/lib/components/ListToolbar/ListToolbar.types.d.ts.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.types.js.map +1 -1
- package/lib/components/ListToolbar/PresetMenuPopover.d.ts +12 -0
- package/lib/components/ListToolbar/PresetMenuPopover.d.ts.map +1 -0
- package/lib/components/ListToolbar/PresetMenuPopover.js +36 -0
- package/lib/components/ListToolbar/PresetMenuPopover.js.map +1 -0
- package/lib/components/ListToolbar/QueryOptionPopover.d.ts.map +1 -1
- package/lib/components/ListToolbar/QueryOptionPopover.js +14 -44
- package/lib/components/ListToolbar/QueryOptionPopover.js.map +1 -1
- package/lib/components/Menu/Menu.d.ts.map +1 -1
- package/lib/components/Menu/Menu.js +8 -5
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/Menu/Menu.styles.js +1 -1
- package/lib/components/Menu/Menu.styles.js.map +1 -1
- package/lib/components/Menu/Menu.types.d.ts +13 -0
- package/lib/components/Menu/Menu.types.d.ts.map +1 -1
- package/lib/components/Menu/Menu.types.js.map +1 -1
- package/lib/components/Menu/MenuGroup.d.ts.map +1 -1
- package/lib/components/Menu/MenuGroup.js +3 -3
- package/lib/components/Menu/MenuGroup.js.map +1 -1
- package/lib/components/Menu/MenuItem.d.ts.map +1 -1
- package/lib/components/Menu/MenuItem.js +3 -5
- package/lib/components/Menu/MenuItem.js.map +1 -1
- package/lib/components/Menu/MenuList.d.ts.map +1 -1
- package/lib/components/Menu/MenuList.js +14 -14
- package/lib/components/Menu/MenuList.js.map +1 -1
- package/lib/components/MetaList/MetaList.d.ts.map +1 -1
- package/lib/components/MetaList/MetaList.js +13 -10
- package/lib/components/MetaList/MetaList.js.map +1 -1
- package/lib/components/Number/NumberInput.d.ts.map +1 -1
- package/lib/components/Number/NumberInput.js +18 -5
- package/lib/components/Number/NumberInput.js.map +1 -1
- package/lib/components/Number/NumberInput.styles.d.ts +6 -2
- package/lib/components/Number/NumberInput.styles.d.ts.map +1 -1
- package/lib/components/Number/NumberInput.styles.js +4 -2
- package/lib/components/Number/NumberInput.styles.js.map +1 -1
- package/lib/components/Number/NumberInput.types.d.ts +2 -0
- package/lib/components/Number/NumberInput.types.d.ts.map +1 -1
- package/lib/components/Number/NumberInput.types.js.map +1 -1
- package/lib/components/PageTemplates/DashboardPage.d.ts.map +1 -1
- package/lib/components/PageTemplates/DashboardPage.js +1 -4
- package/lib/components/PageTemplates/DashboardPage.js.map +1 -1
- package/lib/components/Phone/PhoneInput.d.ts.map +1 -1
- package/lib/components/Phone/PhoneInput.js +12 -3
- package/lib/components/Phone/PhoneInput.js.map +1 -1
- package/lib/components/SearchInput/SearchInput.d.ts +5 -0
- package/lib/components/SearchInput/SearchInput.d.ts.map +1 -1
- package/lib/components/SearchInput/SearchInput.js +14 -4
- package/lib/components/SearchInput/SearchInput.js.map +1 -1
- package/lib/components/SearchInput/SearchInput.styles.d.ts +3 -0
- package/lib/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/lib/components/SearchInput/SearchInput.styles.js +6 -0
- package/lib/components/SearchInput/SearchInput.styles.js.map +1 -1
- package/lib/components/Select/Select.d.ts +2 -0
- package/lib/components/Select/Select.d.ts.map +1 -1
- package/lib/components/Select/Select.js +4 -3
- package/lib/components/Select/Select.js.map +1 -1
- package/lib/components/Skeleton/ParagraphSkeleton.d.ts.map +1 -1
- package/lib/components/Skeleton/ParagraphSkeleton.js +2 -2
- package/lib/components/Skeleton/ParagraphSkeleton.js.map +1 -1
- package/lib/components/Tabs/TabPanel.d.ts.map +1 -1
- package/lib/components/Tabs/TabPanel.js +1 -7
- package/lib/components/Tabs/TabPanel.js.map +1 -1
- package/lib/components/Text/Text.js +2 -2
- package/lib/components/Text/Text.js.map +1 -1
- package/lib/components/TextArea/TextArea.d.ts.map +1 -1
- package/lib/components/TextArea/TextArea.js +4 -2
- package/lib/components/TextArea/TextArea.js.map +1 -1
- package/lib/components/Tooltip/Tooltip.d.ts +5 -0
- package/lib/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/lib/components/Tooltip/Tooltip.js +22 -5
- package/lib/components/Tooltip/Tooltip.js.map +1 -1
- package/lib/hooks/useActiveDescendant.d.ts +5 -1
- package/lib/hooks/useActiveDescendant.d.ts.map +1 -1
- package/lib/hooks/useActiveDescendant.js +166 -95
- package/lib/hooks/useActiveDescendant.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +36 -1
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/hooks/useI18n.js +2 -1
- package/lib/hooks/useI18n.js.map +1 -1
- package/lib/i18n/default.d.ts +36 -1
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +50 -14
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +72 -2
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/i18n/translate.d.ts +3 -0
- package/lib/i18n/translate.d.ts.map +1 -1
- package/lib/i18n/translate.js.map +1 -1
- package/lib/theme/theme.d.ts +12 -0
- package/lib/theme/theme.d.ts.map +1 -1
- package/lib/theme/themeDefinition.json +7 -1
- package/lib/theme/themeOverrides.schema.json +9 -0
- package/lib/theme/themes/darkTheme.json +3 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../../../src/components/Text/Text.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAgC,UAAU,EAAwB,MAAM,OAAO,CAAC;AACvF,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../../../src/components/Text/Text.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAgC,UAAU,EAAwB,MAAM,OAAO,CAAC;AACvF,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAY,MAAM,cAAc,CAAC;AAoB3D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,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AAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,KAAM,SAAS,GAAI,CAAC;AAC3E,CAAC,CACF,CAAC;AAEF,eAAe,IAAI,CAAC","sourcesContent":["import { FunctionComponent, ReactNode, forwardRef, Ref, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\nimport { rgba } from 'polished';\n\nimport { BaseProps, ForwardProps, AsProp, PropsWithDefaults } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport { calculateFontSize, FontSize } from '../../styles';\n\nexport interface TextProps extends BaseProps, AsProp {\n /** Text content. */\n children: ReactNode;\n /**\n * Typographical sizes and styles.\n * @default \"primary\"\n */\n variant?: 'primary' | 'secondary' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n /**\n * Render text with semantic color based on a status.\n */\n status?: 'error' | 'warning' | 'success';\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLSpanElement | HTMLHeadingElement>;\n}\n\ntype TextPropsWithDefaults = PropsWithDefaults<TextProps, 'variant'>;\n\nexport const StyledText = styled.span<TextPropsWithDefaults>(props => {\n const {\n variant,\n status,\n theme: {\n base: {\n 'font-size': fontSize,\n 'font-scale': fontScale,\n palette: { 'foreground-color': foregroundColor, urgent: error, warn: warning, success },\n transparency: { 'transparent-2': secondaryAlpha }\n },\n components: { text }\n }\n } = props;\n\n let color: string | undefined;\n\n if (status) {\n color = {\n error,\n warning,\n success\n }[status];\n }\n\n if (variant === 'secondary') {\n color = tryCatch(() => rgba(color ?? foregroundColor, secondaryAlpha));\n }\n\n const fontSizes = calculateFontSize(fontSize, fontScale);\n\n return css`\n font-size: ${fontSizes[text[variant]['font-size'] as FontSize]};\n font-weight: ${text[variant]['font-weight']};\n color: ${color};\n `;\n});\n\nStyledText.defaultProps = defaultThemeProp;\n\nconst Text: FunctionComponent<TextProps & ForwardProps> = forwardRef(\n (\n { variant = 'primary', as, ...restProps }: PropsWithoutRef<TextProps>,\n ref: TextProps['ref']\n ) => {\n // If variant is for a heading, and no as is passed, set as to heading tag.\n if (!as && /h\\d/i.test(variant)) as = variant as 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n return <StyledText ref={ref} variant={variant} as={as} {...restProps} />;\n }\n);\n\nexport default Text;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAOF,kBAAkB,EAEnB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAqB,MAAM,gBAAgB,CAAC;AAOrE,MAAM,WAAW,aAAc,SAAQ,gBAAgB,EAAE,cAAc;IACrE,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;CACpD;AAED,QAAA,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAOF,kBAAkB,EAEnB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAqB,MAAM,gBAAgB,CAAC;AAOrE,MAAM,WAAW,aAAc,SAAQ,gBAAgB,EAAE,cAAc;IACrE,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;CACpD;AAED,QAAA,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,YAAY,CA2G9C,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -8,7 +8,7 @@ import Text from '../Text';
|
|
|
8
8
|
import StyledTextArea from './TextArea.styles';
|
|
9
9
|
const TextArea = forwardRef((props, ref) => {
|
|
10
10
|
const uid = useUID();
|
|
11
|
-
const { id = uid, value, defaultValue, required = false, disabled = false, label, labelHidden, info, status, resizable = false, autoResize = false, maxLength, displayCharCount = false, hardStop = true, onChange: onChangeProp, ...restProps } = props;
|
|
11
|
+
const { id = uid, value, defaultValue, required = false, disabled = false, label, labelHidden, info, status, resizable = false, autoResize = false, maxLength, displayCharCount = false, hardStop = true, onChange: onChangeProp, onResolveSuggestion, ...restProps } = props;
|
|
12
12
|
const t = useI18n();
|
|
13
13
|
const [textAreaRef, resizeTextArea] = useAutoResize(undefined, 100);
|
|
14
14
|
const consolidatedRef = useConsolidatedRef(textAreaRef, ref);
|
|
@@ -44,6 +44,7 @@ const TextArea = forwardRef((props, ref) => {
|
|
|
44
44
|
status,
|
|
45
45
|
resizable,
|
|
46
46
|
maxLength: hardStop ? maxLength : undefined,
|
|
47
|
+
hasSuggestion: status === 'pending' && !!onResolveSuggestion,
|
|
47
48
|
...controlProp,
|
|
48
49
|
...restProps,
|
|
49
50
|
onChange,
|
|
@@ -57,7 +58,8 @@ const TextArea = forwardRef((props, ref) => {
|
|
|
57
58
|
status,
|
|
58
59
|
charLimitDisplay: displayCharCount && typeof maxLength === 'number' ? (_jsx(Text, { variant: 'secondary', "aria-live": maxLength >= 0 && maxLength - charCount <= 20 ? 'polite' : 'off', children: maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount })) : undefined,
|
|
59
60
|
required,
|
|
60
|
-
disabled
|
|
61
|
+
disabled,
|
|
62
|
+
onResolveSuggestion
|
|
61
63
|
}, children: Comp })) : (Comp);
|
|
62
64
|
});
|
|
63
65
|
export default TextArea;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,UAAU,EAGV,WAAW,EACX,QAAQ,EAER,SAAS,EACV,MAAM,OAAO,CAAC;AAGf,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,cAAc,MAAM,mBAAmB,CAAC;AA8B/C,MAAM,QAAQ,GAAqC,UAAU,CAC3D,CAAC,KAAqC,EAAE,GAA6B,EAAE,EAAE;IACvE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EACJ,EAAE,GAAG,GAAG,EACR,KAAK,EACL,YAAY,EACZ,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,EAChB,KAAK,EACL,WAAW,EACX,IAAI,EACJ,MAAM,EACN,SAAS,GAAG,KAAK,E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GAAG;YACvC,EAAE;YACF,QAAQ;YACR,QAAQ;YACR,MAAM;YACN,SAAS;YACT,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YAC3C,aAAa,EAAE,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,mBAAmB;YAC5D,GAAG,WAAW;YACd,GAAG,SAAS;YACZ,QAAQ;YACR,EAAE,EAAE,cAAc;SACnB,GACD,CACH,CAAC;IAEF,OAAO,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC,CACjC,KAAC,SAAS,OACJ;YACF,KAAK;YACL,WAAW;YACX,EAAE;YACF,IAAI;YACJ,MAAM;YACN,gBAAgB,EACd,gBAAgB,IAAI,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,CAClD,KAAC,IAAI,IACH,OAAO,EAAC,WAAW,eACR,SAAS,IAAI,CAAC,IAAI,SAAS,GAAG,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,YAE1E,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,IAAI,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GACnE,CACR,CAAC,CAAC,CAAC,SAAS;YACf,QAAQ;YACR,QAAQ;YACR,mBAAmB;SACpB,YAEA,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import {\n FC,\n Ref,\n forwardRef,\n PropsWithoutRef,\n ChangeEvent,\n useCallback,\n useState,\n ChangeEventHandler,\n useEffect\n} from 'react';\n\nimport { ForwardProps, NoChildrenProp } from '../../types';\nimport FormField from '../FormField';\nimport { FormControlProps, StyledFormControl } from '../FormControl';\nimport { hasProp } from '../../utils';\nimport { useAutoResize, useConsolidatedRef, useI18n, useUID } from '../../hooks';\nimport Text from '../Text';\n\nimport StyledTextArea from './TextArea.styles';\n\nexport interface TextAreaProps extends FormControlProps, NoChildrenProp {\n /** Minimum length of characters that can be input. */\n minLength?: number;\n /** Maximum length of characters that can be input. */\n maxLength?: number;\n /**\n * Allows the user to resize the Text Area.\n * @default false\n */\n resizable?: boolean;\n /**\n * Enables the Text Area to resize itself automatically.\n * @default false\n */\n autoResize?: boolean;\n /**\n * Display a live character count in relation to the maxLength.\n * @default false\n */\n displayCharCount?: boolean;\n /**\n * Allow or disallow a value beyond the maxLength.\n * @default true\n */\n hardStop?: boolean;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n}\n\nconst TextArea: FC<TextAreaProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<TextAreaProps>, ref: Ref<HTMLTextAreaElement>) => {\n const uid = useUID();\n const {\n id = uid,\n value,\n defaultValue,\n required = false,\n disabled = false,\n label,\n labelHidden,\n info,\n status,\n resizable = false,\n autoResize = false,\n maxLength,\n displayCharCount = false,\n hardStop = true,\n onChange: onChangeProp,\n onResolveSuggestion,\n ...restProps\n } = props;\n\n const t = useI18n();\n\n const [textAreaRef, resizeTextArea] = useAutoResize<HTMLTextAreaElement>(undefined, 100);\n const consolidatedRef = useConsolidatedRef(textAreaRef, ref);\n const [charCount, setCharCount] = useState(0);\n\n const controlProp: {\n value?: string;\n defaultValue?: string;\n } = {};\n\n useEffect(() => {\n if (hasProp(props, 'value')) {\n setCharCount(props.value ? props.value.length : 0);\n } else if (hasProp(props, 'defaultValue')) {\n setCharCount(props.defaultValue ? props.defaultValue.length : 0);\n }\n }, [props]);\n\n // Conditionally render component as controlled/uncontrolled\n if (hasProp(props, 'value')) {\n controlProp.value = value ?? '';\n } else if (hasProp(props, 'defaultValue')) {\n controlProp.defaultValue = defaultValue ?? '';\n }\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLTextAreaElement>) => {\n if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {\n onChangeProp?.(e);\n setCharCount(e.target.value.length);\n resizeTextArea();\n }\n },\n [onChangeProp, resizeTextArea, hardStop, maxLength]\n );\n\n const Comp = (\n <StyledFormControl\n {...{\n ref: autoResize ? consolidatedRef : ref,\n id,\n required,\n disabled,\n status,\n resizable,\n maxLength: hardStop ? maxLength : undefined,\n hasSuggestion: status === 'pending' && !!onResolveSuggestion,\n ...controlProp,\n ...restProps,\n onChange,\n as: StyledTextArea\n }}\n />\n );\n\n return label || displayCharCount ? (\n <FormField\n {...{\n label,\n labelHidden,\n id,\n info,\n status,\n charLimitDisplay:\n displayCharCount && typeof maxLength === 'number' ? (\n <Text\n variant='secondary'\n aria-live={maxLength >= 0 && maxLength - charCount <= 20 ? 'polite' : 'off'}\n >\n {maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount}\n </Text>\n ) : undefined,\n required,\n disabled,\n onResolveSuggestion\n }}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default TextArea;\n"]}
|
|
@@ -26,6 +26,11 @@ export interface TooltipProps extends BaseProps {
|
|
|
26
26
|
* @default true
|
|
27
27
|
*/
|
|
28
28
|
describeTarget?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the placement of the tooltip relative to the target.
|
|
31
|
+
* @default "bottom"
|
|
32
|
+
*/
|
|
33
|
+
placement?: PopoverProps['placement'];
|
|
29
34
|
ref?: Ref<HTMLDivElement>;
|
|
30
35
|
}
|
|
31
36
|
export declare const StyledTooltip: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAGjB,GAAG,EAKJ,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAgB,EAAE,K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AO,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;IACtC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,aAAa,yGAaxB,CAAC;AAIH,QAAA,MAAM,OAAO,EAAE,iBAAiB,CAAC,YAAY,GAAG,YAAY,CA8H3D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -19,7 +19,7 @@ export const StyledTooltip = styled.div(({ theme }) => {
|
|
|
19
19
|
`;
|
|
20
20
|
});
|
|
21
21
|
StyledTooltip.defaultProps = defaultThemeProp;
|
|
22
|
-
const Tooltip = forwardRef(({ children, target, showDelay = 'short', hideDelay = 'long', portal = false, describeTarget = true, ...restProps }, ref) => {
|
|
22
|
+
const Tooltip = forwardRef(({ children, target, showDelay = 'short', hideDelay = 'long', portal = false, placement = 'bottom', describeTarget = true, ...restProps }, ref) => {
|
|
23
23
|
const id = useUID();
|
|
24
24
|
const [show, setShow] = useState(false);
|
|
25
25
|
const tooltipRef = useConsolidatedRef(ref);
|
|
@@ -71,11 +71,28 @@ const Tooltip = forwardRef(({ children, target, showDelay = 'short', hideDelay =
|
|
|
71
71
|
};
|
|
72
72
|
}, [target, showTooltip, onMouseDown, onFocusOut, onMouseLeave, onKeyDown]);
|
|
73
73
|
useEffect(() => {
|
|
74
|
-
if (target &&
|
|
75
|
-
target.
|
|
74
|
+
if (target && describeTarget && show) {
|
|
75
|
+
const describedBy = target.getAttribute('aria-describedby');
|
|
76
|
+
// Set the attribute to the old attribute plus the id
|
|
77
|
+
target.setAttribute('aria-describedby', describedBy ? `${describedBy} ${id}` : id);
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
else if (target) {
|
|
80
|
+
// Get the old attribute
|
|
81
|
+
const describedBy = target.getAttribute('aria-describedby');
|
|
82
|
+
if (describedBy) {
|
|
83
|
+
// If the old attribute matches the id just remove it entirely
|
|
84
|
+
if (describedBy === id) {
|
|
85
|
+
target.removeAttribute('aria-describedby');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Otherwise we want to just remove the id that was added and reset the attribute to what it was before
|
|
89
|
+
const oldDescribedBy = describedBy.replace(new RegExp(`(?:^|\\s+)${id}`), '');
|
|
90
|
+
target.setAttribute('aria-describedby', oldDescribedBy);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, [describeTarget, target, show]);
|
|
95
|
+
return (_jsx(Popover, { id: id, ...restProps, show: show, showDelay: showDelay, hideDelay: hideDelay, groupId: 'tooltip', strategy: 'fixed', portal: portal, as: StyledTooltip, role: 'tooltip', target: target, arrow: true, placement: placement, onMouseDown: onMouseDown, hideOnTargetHidden: true, ref: tooltipRef, children: children }));
|
|
79
96
|
});
|
|
80
97
|
export default Tooltip;
|
|
81
98
|
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAKV,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,OAAgC,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AA8BjD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACpD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,KAA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ef,\n Ref,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { BaseProps, ForwardProps } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Popover, { Delay, PopoverProps } from '../Popover';\nimport { useConsolidatedRef, useUID } from '../../hooks';\nimport { calculateFontSize } from '../../styles';\n\nexport interface TooltipProps extends BaseProps {\n /** Text content for the tooltip. */\n children: string | string[];\n /** Element to serve as the tooltip's target. */\n target: Element | null;\n /**\n * Delay showing the tooltip on mouseenter.\n * @default \"short\"\n */\n showDelay?: Delay;\n /**\n * Delay hiding the tooltip on mouseleave.\n * @default \"long\"\n */\n hideDelay?: Delay;\n /**\n * If true, the Tooltip will render outside of the current DOM hierarchy in a [portal](https://reactjs.org/docs/portals.html).\n * @default false\n */\n portal?: PopoverProps['portal'];\n /**\n * If true, the Tooltip will automatically apply an aria-describedby attribute to its target.\n * @default true\n */\n describeTarget?: boolean;\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const StyledTooltip = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n background-color: ${theme.components.tooltip['background-color']};\n color: ${theme.components.tooltip['foreground-color']};\n font-size: ${fontSize.xxs};\n max-width: 40ch;\n padding: ${theme.base.spacing};\n white-space: pre-line;\n word-break: break-word;\n pointer-events: none;\n `;\n});\n\nStyledTooltip.defaultProps = defaultThemeProp;\n\nconst Tooltip: FunctionComponent<TooltipProps & ForwardProps> = forwardRef(\n (\n {\n children,\n target,\n showDelay = 'short',\n hideDelay = 'long',\n portal = false,\n describeTarget = true,\n ...restProps\n }: PropsWithoutRef<TooltipProps>,\n ref: Ref<HTMLDivElement>\n ) => {\n const id = useUID();\n const [show, setShow] = useState(false);\n const tooltipRef = useConsolidatedRef(ref);\n const lastClickedRef: MutableRefObject<EventTarget | null> = useRef(null);\n\n const showTooltip = useCallback(() => {\n setShow(true);\n }, []);\n\n const onMouseDown = useCallback(\n ({ target: eTarget }: MouseEvent) => {\n lastClickedRef.current = eTarget;\n if (eTarget === tooltipRef.current || eTarget === target) return;\n setShow(false);\n },\n [target]\n );\n\n const onFocusOut = useCallback(() => {\n if (lastClickedRef.current !== tooltipRef.current) {\n setShow(false);\n }\n lastClickedRef.current = null;\n }, []);\n\n const onMouseEnter = useCallback(() => {\n setShow(true);\n }, [target]);\n\n const onMouseLeave = useCallback(() => {\n if (document.activeElement !== target) {\n setShow(false);\n }\n }, [target]);\n\n const onKeyDown = useCallback(\n ({ key }: KeyboardEvent) => {\n if (key === 'Escape' && document.activeElement === target) {\n setShow(false);\n }\n },\n [target]\n );\n\n useEffect(() => {\n if (!target) return;\n\n document.addEventListener('keydown', onKeyDown);\n document.addEventListener('mousedown', onMouseDown);\n\n target.addEventListener('focusin', showTooltip);\n target.addEventListener('focusout', onFocusOut);\n\n target.addEventListener('mouseenter', onMouseEnter);\n target.addEventListener('mouseleave', onMouseLeave);\n\n return () => {\n document.removeEventListener('keydown', onKeyDown);\n document.removeEventListener('mousedown', onMouseDown);\n\n target.removeEventListener('focusin', showTooltip);\n target.removeEventListener('focusout', onFocusOut);\n\n target.removeEventListener('mouseenter', onMouseEnter);\n target.removeEventListener('mouseleave', onMouseLeave);\n };\n }, [target, showTooltip, onMouseDown, onFocusOut, onMouseLeave, onKeyDown]);\n\n useEffect(() => {\n if (target && !target.getAttribute('aria-describedby') && describeTarget) {\n target.setAttribute('aria-describedby', id);\n }\n }, [describeTarget, target]);\n\n return (\n <Popover\n id={id}\n {...restProps}\n show={show}\n showDelay={showDelay}\n hideDelay={hideDelay}\n groupId='tooltip'\n strategy='fixed'\n portal={portal}\n as={StyledTooltip}\n role='tooltip'\n target={target}\n arrow\n placement='bottom'\n onMouseDown={onMouseDown}\n hideOnTargetHidden\n ref={tooltipRef}\n >\n {children}\n </Popover>\n );\n }\n);\n\nexport default Tooltip;\n"]}
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/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qDAAqD;YACrD,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACpF;aAAM,IAAI,MAAM,EAAE;YACjB,wBAAwB;YACxB,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;YAC5D,IAAI,WAAW,EAAE;gBACf,8DAA8D;gBAC9D,IAAI,WAAW,KAAK,EAAE,EAAE;oBACtB,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;iBAC5C;qBAAM;oBACL,uGAAuG;oBACvG,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,aAAa,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;oBAC9E,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;iBACzD;aACF;SACF;IACH,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEnC,OAAO,CACL,KAAC,OAAO,IACN,EAAE,EAAE,EAAE,KACF,SAAS,EACb,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAC,SAAS,EACjB,QAAQ,EAAC,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,IAAI,EAAC,SAAS,EACd,MAAM,EAAE,MAAM,EACd,KAAK,QACL,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,kBAAkB,QAClB,GAAG,EAAE,UAAU,YAEd,QAAQ,GACD,CACX,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n MutableRefObject,\n PropsWithoutRef,\n Ref,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { BaseProps, ForwardProps } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Popover, { Delay, PopoverProps } from '../Popover';\nimport { useConsolidatedRef, useUID } from '../../hooks';\nimport { calculateFontSize } from '../../styles';\n\nexport interface TooltipProps extends BaseProps {\n /** Text content for the tooltip. */\n children: string | string[];\n /** Element to serve as the tooltip's target. */\n target: Element | null;\n /**\n * Delay showing the tooltip on mouseenter.\n * @default \"short\"\n */\n showDelay?: Delay;\n /**\n * Delay hiding the tooltip on mouseleave.\n * @default \"long\"\n */\n hideDelay?: Delay;\n /**\n * If true, the Tooltip will render outside of the current DOM hierarchy in a [portal](https://reactjs.org/docs/portals.html).\n * @default false\n */\n portal?: PopoverProps['portal'];\n /**\n * If true, the Tooltip will automatically apply an aria-describedby attribute to its target.\n * @default true\n */\n describeTarget?: boolean;\n /**\n * Sets the placement of the tooltip relative to the target.\n * @default \"bottom\"\n */\n placement?: PopoverProps['placement'];\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const StyledTooltip = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n background-color: ${theme.components.tooltip['background-color']};\n color: ${theme.components.tooltip['foreground-color']};\n font-size: ${fontSize.xxs};\n max-width: 40ch;\n padding: ${theme.base.spacing};\n white-space: pre-line;\n word-break: break-word;\n pointer-events: none;\n `;\n});\n\nStyledTooltip.defaultProps = defaultThemeProp;\n\nconst Tooltip: FunctionComponent<TooltipProps & ForwardProps> = forwardRef(\n (\n {\n children,\n target,\n showDelay = 'short',\n hideDelay = 'long',\n portal = false,\n placement = 'bottom',\n describeTarget = true,\n ...restProps\n }: PropsWithoutRef<TooltipProps>,\n ref: Ref<HTMLDivElement>\n ) => {\n const id = useUID();\n const [show, setShow] = useState(false);\n const tooltipRef = useConsolidatedRef(ref);\n const lastClickedRef: MutableRefObject<EventTarget | null> = useRef(null);\n\n const showTooltip = useCallback(() => {\n setShow(true);\n }, []);\n\n const onMouseDown = useCallback(\n ({ target: eTarget }: MouseEvent) => {\n lastClickedRef.current = eTarget;\n if (eTarget === tooltipRef.current || eTarget === target) return;\n setShow(false);\n },\n [target]\n );\n\n const onFocusOut = useCallback(() => {\n if (lastClickedRef.current !== tooltipRef.current) {\n setShow(false);\n }\n lastClickedRef.current = null;\n }, []);\n\n const onMouseEnter = useCallback(() => {\n setShow(true);\n }, [target]);\n\n const onMouseLeave = useCallback(() => {\n if (document.activeElement !== target) {\n setShow(false);\n }\n }, [target]);\n\n const onKeyDown = useCallback(\n ({ key }: KeyboardEvent) => {\n if (key === 'Escape' && document.activeElement === target) {\n setShow(false);\n }\n },\n [target]\n );\n\n useEffect(() => {\n if (!target) return;\n\n document.addEventListener('keydown', onKeyDown);\n document.addEventListener('mousedown', onMouseDown);\n\n target.addEventListener('focusin', showTooltip);\n target.addEventListener('focusout', onFocusOut);\n\n target.addEventListener('mouseenter', onMouseEnter);\n target.addEventListener('mouseleave', onMouseLeave);\n\n return () => {\n document.removeEventListener('keydown', onKeyDown);\n document.removeEventListener('mousedown', onMouseDown);\n\n target.removeEventListener('focusin', showTooltip);\n target.removeEventListener('focusout', onFocusOut);\n\n target.removeEventListener('mouseenter', onMouseEnter);\n target.removeEventListener('mouseleave', onMouseLeave);\n };\n }, [target, showTooltip, onMouseDown, onFocusOut, onMouseLeave, onKeyDown]);\n\n useEffect(() => {\n if (target && describeTarget && show) {\n const describedBy = target.getAttribute('aria-describedby');\n // Set the attribute to the old attribute plus the id\n target.setAttribute('aria-describedby', describedBy ? `${describedBy} ${id}` : id);\n } else if (target) {\n // Get the old attribute\n const describedBy = target.getAttribute('aria-describedby');\n if (describedBy) {\n // If the old attribute matches the id just remove it entirely\n if (describedBy === id) {\n target.removeAttribute('aria-describedby');\n } else {\n // Otherwise we want to just remove the id that was added and reset the attribute to what it was before\n const oldDescribedBy = describedBy.replace(new RegExp(`(?:^|\\\\s+)${id}`), '');\n target.setAttribute('aria-describedby', oldDescribedBy);\n }\n }\n }\n }, [describeTarget, target, show]);\n\n return (\n <Popover\n id={id}\n {...restProps}\n show={show}\n showDelay={showDelay}\n hideDelay={hideDelay}\n groupId='tooltip'\n strategy='fixed'\n portal={portal}\n as={StyledTooltip}\n role='tooltip'\n target={target}\n arrow\n placement={placement}\n onMouseDown={onMouseDown}\n hideOnTargetHidden\n ref={tooltipRef}\n >\n {children}\n </Popover>\n );\n }\n);\n\nexport default Tooltip;\n"]}
|
|
@@ -8,6 +8,10 @@ export interface UseActiveDescendantConfig {
|
|
|
8
8
|
scopeSelector?: string;
|
|
9
9
|
/** Custom selector for descendant options */
|
|
10
10
|
selector?: string;
|
|
11
|
+
/** Orientation of descendant navigation
|
|
12
|
+
* @default 'vertical'
|
|
13
|
+
*/
|
|
14
|
+
orientation?: 'horizontal' | 'vertical';
|
|
11
15
|
/** One-time override for the focused descendant, triggers re-evaluation.
|
|
12
16
|
* Include `clearFocusDescendantEl` for cleanup.
|
|
13
17
|
*/
|
|
@@ -43,7 +47,7 @@ export interface UseActiveDescendantConfig {
|
|
|
43
47
|
}
|
|
44
48
|
declare type CurrentDescendant = HTMLElement | undefined;
|
|
45
49
|
declare type Descendants = HTMLElement[] | null;
|
|
46
|
-
declare const useActiveDescendant: ({ focusEl, scope, scopeSelector, selector, focusDescendantEl, clearFocusDescendant, focusReturnEl, clearFocusReturn, currentDescendantId, onClick, preventInitialScroll, pauseDescendantEvaluation, clearPreventScroll }: UseActiveDescendantConfig, dependencyArray?: DependencyList) => {
|
|
50
|
+
declare const useActiveDescendant: ({ focusEl, scope, scopeSelector, selector, orientation, focusDescendantEl, clearFocusDescendant, focusReturnEl, clearFocusReturn, currentDescendantId, onClick, preventInitialScroll, pauseDescendantEvaluation, clearPreventScroll }: UseActiveDescendantConfig, dependencyArray?: DependencyList) => {
|
|
47
51
|
activeDescendant: CurrentDescendant;
|
|
48
52
|
descendants: Descendants;
|
|
49
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveDescendant.d.ts","sourceRoot":"","sources":["../../src/hooks/useActiveDescendant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,cAAc,EAAuB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useActiveDescendant.d.ts","sourceRoot":"","sources":["../../src/hooks/useActiveDescendant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,cAAc,EAAuB,MAAM,OAAO,CAAC;AAMjF,MAAM,WAAW,yBAAyB;IACxC,4DAA4D;IAC5D,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,wCAAwC;IACxC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACxC;;OAEG;IACH,iBAAiB,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACvC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC;;OAEG;IACH,aAAa,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,+DAA+D;IAC/D,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,WAAW,KAAK,IAAI,CAAC;IACrD;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC;;OAEG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,aAAK,iBAAiB,GAAG,WAAW,GAAG,SAAS,CAAC;AACjD,aAAK,WAAW,GAAG,WAAW,EAAE,GAAG,IAAI,CAAC;AAExC,QAAA,MAAM,mBAAmB,0OAgBpB,yBAAyB;sBAGV,iBAAiB;iBACtB,WAAW;CAwTzB,CAAC;AAEF,eAAO,MAAM,iBAAiB;aASnB,OAAO;iBACH,WAAW;8BACE,iBAAiB;sBACzB,iBAAiB;mBACpB,yBAAyB,CAAC,eAAe,CAAC;2BAClC,WAAW,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI;;UAmC/D,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -1,29 +1,76 @@
|
|
|
1
1
|
import { useEffect, useState, useCallback, useRef } from 'react';
|
|
2
2
|
import { createUID } from '../utils';
|
|
3
|
-
|
|
3
|
+
import useDirection from './useDirection';
|
|
4
|
+
const useActiveDescendant = ({ focusEl, scope, scopeSelector, selector, orientation = 'vertical', focusDescendantEl, clearFocusDescendant, focusReturnEl, clearFocusReturn, currentDescendantId, onClick, preventInitialScroll, pauseDescendantEvaluation = false, clearPreventScroll }, dependencyArray = []) => {
|
|
4
5
|
const [resetId, setResetId] = useState(0);
|
|
5
6
|
const previousActiveId = useRef('');
|
|
7
|
+
const paused = useRef(pauseDescendantEvaluation);
|
|
6
8
|
const [focusDescendantElIndex, setFocusDescendantElIndex] = useState(null);
|
|
7
9
|
const [currentIndex, setCurrentIndex] = useState(null);
|
|
8
10
|
const [descendants, setDescendants] = useState();
|
|
9
|
-
const
|
|
11
|
+
const { rtl } = useDirection();
|
|
12
|
+
const clearDescendants = useCallback(() => {
|
|
10
13
|
descendants?.forEach(node => {
|
|
11
14
|
node.setAttribute('data-current', 'false');
|
|
12
15
|
});
|
|
16
|
+
}, [descendants]);
|
|
17
|
+
const clearThenSetDescendants = useCallback((setVal) => {
|
|
18
|
+
clearDescendants();
|
|
13
19
|
setDescendants(setVal
|
|
14
20
|
? Array.from(setVal).filter((item) => item instanceof HTMLElement)
|
|
15
21
|
: null);
|
|
16
22
|
}, [descendants]);
|
|
23
|
+
const setIdsAndOwns = useCallback(({ clear } = { clear: false }) => {
|
|
24
|
+
const ownedIds = [];
|
|
25
|
+
if (descendants && descendants.length) {
|
|
26
|
+
descendants.forEach(node => {
|
|
27
|
+
node.id = node.id || createUID();
|
|
28
|
+
ownedIds.push(node.id);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (clear) {
|
|
32
|
+
const currentOwnedIds = focusEl?.getAttribute('aria-owns')?.split(' ');
|
|
33
|
+
const clearedIds = currentOwnedIds?.filter(id => !ownedIds.includes(id));
|
|
34
|
+
focusEl?.setAttribute('aria-owns', clearedIds?.join(' ') || '');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
focusEl?.setAttribute('aria-owns', ownedIds.join(' '));
|
|
38
|
+
}
|
|
39
|
+
}, [focusEl, descendants]);
|
|
40
|
+
const updateDescendants = useCallback(() => {
|
|
41
|
+
if (pauseDescendantEvaluation)
|
|
42
|
+
return;
|
|
43
|
+
let hasScope = scope;
|
|
44
|
+
if (hasScope && hasScope instanceof HTMLElement) {
|
|
45
|
+
if (scopeSelector) {
|
|
46
|
+
hasScope = hasScope.querySelector(scopeSelector);
|
|
47
|
+
}
|
|
48
|
+
if (!hasScope) {
|
|
49
|
+
clearThenSetDescendants(null);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (selector) {
|
|
53
|
+
const setVal = hasScope.querySelectorAll(selector);
|
|
54
|
+
clearThenSetDescendants(setVal);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const setVal = hasScope.querySelectorAll('a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])');
|
|
58
|
+
clearThenSetDescendants(setVal);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
clearThenSetDescendants(null);
|
|
63
|
+
}
|
|
64
|
+
}, [scope, scopeSelector, selector, pauseDescendantEvaluation]);
|
|
65
|
+
// ## Update paused ref
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
paused.current = pauseDescendantEvaluation;
|
|
68
|
+
}, [pauseDescendantEvaluation]);
|
|
17
69
|
// ## Toggle active scope data attr.
|
|
18
70
|
useEffect(() => {
|
|
19
71
|
if (!scope || !focusEl)
|
|
20
72
|
return;
|
|
21
|
-
|
|
22
|
-
let activeElement = rootNode.activeElement;
|
|
23
|
-
if (activeElement?.tagName === 'IFRAME') {
|
|
24
|
-
activeElement = activeElement.contentDocument?.activeElement;
|
|
25
|
-
}
|
|
26
|
-
scope.setAttribute('data-active-scope', activeElement === focusEl ? 'true' : 'false');
|
|
73
|
+
scope.setAttribute('data-active-scope', document.activeElement === focusEl ? 'true' : 'false');
|
|
27
74
|
const onFocus = () => {
|
|
28
75
|
scope.setAttribute('data-active-scope', 'true');
|
|
29
76
|
};
|
|
@@ -39,117 +86,139 @@ const useActiveDescendant = ({ focusEl, scope, scopeSelector, selector, focusDes
|
|
|
39
86
|
}, [scope, focusEl]);
|
|
40
87
|
// ## Update descendants
|
|
41
88
|
useEffect(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
if (selector) {
|
|
55
|
-
clearThenSetDescendants(hasScope.querySelectorAll(selector));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
clearThenSetDescendants(hasScope.querySelectorAll('a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])'));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
clearThenSetDescendants(null);
|
|
63
|
-
}
|
|
64
|
-
}, 0);
|
|
89
|
+
/**
|
|
90
|
+
* 0 second timeout added because descendantScope needs to be
|
|
91
|
+
* up to date before running query after dependencyArray change
|
|
92
|
+
*/
|
|
93
|
+
const timeoutId = setTimeout(updateDescendants, 0);
|
|
94
|
+
return () => clearTimeout(timeoutId);
|
|
95
|
+
}, [...dependencyArray]);
|
|
96
|
+
// ## Reset base current index when dependencies change
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!paused.current) {
|
|
99
|
+
setCurrentIndex(0);
|
|
65
100
|
}
|
|
66
|
-
}, [
|
|
101
|
+
}, [...dependencyArray]);
|
|
67
102
|
// ## Set IDs and aria-owns
|
|
68
103
|
useEffect(() => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
descendants.forEach(node => {
|
|
73
|
-
node.id = node.id || createUID();
|
|
74
|
-
ownedIds.push(node.id);
|
|
75
|
-
});
|
|
104
|
+
if (!pauseDescendantEvaluation) {
|
|
105
|
+
setIdsAndOwns();
|
|
106
|
+
setResetId(Math.random());
|
|
76
107
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}, [focusEl, descendants]);
|
|
108
|
+
else {
|
|
109
|
+
clearDescendants();
|
|
110
|
+
setIdsAndOwns({ clear: true });
|
|
111
|
+
}
|
|
112
|
+
}, [pauseDescendantEvaluation, focusEl, descendants]);
|
|
82
113
|
// ## Bind focus el keyDown
|
|
83
114
|
useEffect(() => {
|
|
115
|
+
const nextIndex = () => {
|
|
116
|
+
// Focus next or first
|
|
117
|
+
clearFocusReturn?.();
|
|
118
|
+
clearPreventScroll?.();
|
|
119
|
+
if (currentIndex !== null && currentIndex + 1 < descendants.length) {
|
|
120
|
+
setCurrentIndex(currentIndex + 1);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
setCurrentIndex(0);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const prevIndex = () => {
|
|
127
|
+
// Focus previous or last
|
|
128
|
+
clearFocusReturn?.();
|
|
129
|
+
clearPreventScroll?.();
|
|
130
|
+
if (currentIndex !== null && currentIndex - 1 > -1) {
|
|
131
|
+
setCurrentIndex(currentIndex - 1);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
setCurrentIndex(descendants.length - 1);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
84
137
|
const onKeyDown = (e) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
setCurrentIndex(currentIndex + 1);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
setCurrentIndex(0);
|
|
97
|
-
}
|
|
98
|
-
break;
|
|
99
|
-
case 'ArrowUp':
|
|
100
|
-
e.preventDefault();
|
|
101
|
-
// Focus previous or last
|
|
102
|
-
clearFocusReturn?.();
|
|
103
|
-
clearPreventScroll?.();
|
|
104
|
-
if (currentIndex !== null && currentIndex - 1 > -1) {
|
|
105
|
-
setCurrentIndex(currentIndex - 1);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
setCurrentIndex(descendants.length - 1);
|
|
109
|
-
}
|
|
110
|
-
break;
|
|
111
|
-
case 'Enter':
|
|
112
|
-
e.preventDefault();
|
|
113
|
-
// Click focused item
|
|
114
|
-
if (descendants && descendants.length && currentIndex !== null) {
|
|
115
|
-
if (onClick) {
|
|
116
|
-
onClick(descendants[currentIndex]);
|
|
117
|
-
break;
|
|
138
|
+
// 0 second timeout to execute after explicitly defined onKeyDown event handlers.
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
if (descendants && descendants.length) {
|
|
141
|
+
switch (e.key) {
|
|
142
|
+
case 'ArrowDown':
|
|
143
|
+
if (orientation === 'vertical') {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
nextIndex();
|
|
118
146
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
147
|
+
break;
|
|
148
|
+
case 'ArrowUp':
|
|
149
|
+
if (orientation === 'vertical') {
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
prevIndex();
|
|
122
152
|
}
|
|
123
|
-
|
|
124
|
-
|
|
153
|
+
break;
|
|
154
|
+
case 'ArrowRight':
|
|
155
|
+
if (orientation === 'horizontal') {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
if (rtl) {
|
|
158
|
+
prevIndex();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
nextIndex();
|
|
162
|
+
}
|
|
125
163
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
164
|
+
break;
|
|
165
|
+
case 'ArrowLeft':
|
|
166
|
+
if (orientation === 'horizontal') {
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
if (rtl) {
|
|
169
|
+
nextIndex();
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
prevIndex();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case 'Enter':
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
// Click focused item
|
|
179
|
+
if (descendants && descendants.length && currentIndex !== null) {
|
|
180
|
+
if (onClick) {
|
|
181
|
+
onClick(descendants[currentIndex]);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
const nodeName = descendants[currentIndex].nodeName.toLowerCase();
|
|
185
|
+
if (nodeName === 'input' || nodeName === 'button' || nodeName === 'a') {
|
|
186
|
+
descendants[currentIndex].click();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
descendants[currentIndex].querySelector('button, a, input')?.click();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
130
196
|
}
|
|
131
|
-
}
|
|
197
|
+
}, 0);
|
|
132
198
|
};
|
|
133
|
-
// Do not rebind once / if `currentDescendantId` control is defined
|
|
134
|
-
if (focusEl && descendants?.length && !currentDescendantId) {
|
|
199
|
+
// Do not rebind once / if `currentDescendantId` (deprecated) control is defined
|
|
200
|
+
if (!pauseDescendantEvaluation && focusEl && descendants?.length && !currentDescendantId) {
|
|
135
201
|
focusEl.addEventListener('keydown', onKeyDown);
|
|
136
202
|
}
|
|
137
203
|
return () => {
|
|
138
204
|
focusEl?.removeEventListener('keydown', onKeyDown);
|
|
139
205
|
};
|
|
140
|
-
}, [focusEl, currentIndex, descendants]);
|
|
141
|
-
// ## Handle independent control update
|
|
206
|
+
}, [focusEl, currentIndex, descendants, pauseDescendantEvaluation]);
|
|
207
|
+
// ## Handle independent control update (deprecated)
|
|
142
208
|
useEffect(() => {
|
|
143
|
-
if (descendants && currentDescendantId) {
|
|
209
|
+
if (!pauseDescendantEvaluation && descendants && currentDescendantId) {
|
|
144
210
|
descendants.forEach((node, index) => {
|
|
145
211
|
if (node.id === currentDescendantId) {
|
|
146
212
|
setCurrentIndex(index);
|
|
147
213
|
}
|
|
148
214
|
});
|
|
149
215
|
}
|
|
150
|
-
}, [currentDescendantId, descendants]);
|
|
216
|
+
}, [currentDescendantId, descendants, pauseDescendantEvaluation]);
|
|
151
217
|
// ## Set and scroll to current descendant
|
|
152
218
|
useEffect(() => {
|
|
219
|
+
if (paused.current) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
153
222
|
const nextIndex = focusDescendantElIndex || currentIndex;
|
|
154
223
|
const focusReturnId = focusReturnEl?.id;
|
|
155
224
|
let focusReturnIndex;
|
|
@@ -215,13 +284,14 @@ export const useLazyDescendant = ({ loading, descendants, previousActiveDescenda
|
|
|
215
284
|
const descendantList = [...descendants];
|
|
216
285
|
const lastItem = descendantList.pop();
|
|
217
286
|
const lastId = lastItem?.id || undefined;
|
|
287
|
+
let timeoutId;
|
|
218
288
|
if (lastId === activeDescendant.id) {
|
|
219
289
|
if (scrollEl) {
|
|
220
290
|
scrollEl.scrollTop = scrollEl.scrollHeight - scrollEl.offsetHeight;
|
|
221
291
|
}
|
|
222
292
|
if (focusReturnEl?.id !== activeDescendant.id) {
|
|
223
293
|
// Set focus return to AD on 'nextTick', to avoid reset of AD on update
|
|
224
|
-
setTimeout(() => {
|
|
294
|
+
timeoutId = setTimeout(() => {
|
|
225
295
|
setFocusReturnEl(lastItem);
|
|
226
296
|
}, 0);
|
|
227
297
|
}
|
|
@@ -230,10 +300,11 @@ export const useLazyDescendant = ({ loading, descendants, previousActiveDescenda
|
|
|
230
300
|
else if (focusReturnEl?.id !== activeDescendant.id) {
|
|
231
301
|
// Set focus return to AD on 'nextTick' to avoid reset of AD on update
|
|
232
302
|
// Do not D.R.Y to avoid conflicting calls with immediately prior elements.
|
|
233
|
-
setTimeout(() => {
|
|
303
|
+
timeoutId = setTimeout(() => {
|
|
234
304
|
setFocusReturnEl(activeDescendant);
|
|
235
305
|
}, 0);
|
|
236
306
|
}
|
|
307
|
+
return () => clearTimeout(timeoutId);
|
|
237
308
|
}
|
|
238
309
|
}, [loading, descendants, previousActiveDescendant, activeDescendant, scrollEl, focusReturnEl]);
|
|
239
310
|
};
|