diff --git a/.betterer.results b/.betterer.results index 9a2bd1a8c8d..83032798feb 100644 --- a/.betterer.results +++ b/.betterer.results @@ -4107,12 +4107,6 @@ exports[`better eslint`] = { "public/app/features/search/utils.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/serviceaccounts/components/CreateTokenModal.tsx:5381": [ - [0, 0, 0, "Styles should be written using objects.", "0"], - [0, 0, 0, "Styles should be written using objects.", "1"], - [0, 0, 0, "Styles should be written using objects.", "2"], - [0, 0, 0, "Styles should be written using objects.", "3"] - ], "public/app/features/serviceaccounts/components/ServiceAccountProfile.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], diff --git a/packages/grafana-ui/src/components/DateTimePickers/DatePicker/DatePicker.tsx b/packages/grafana-ui/src/components/DateTimePickers/DatePicker/DatePicker.tsx index c2a7d8f6457..358d985a169 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/DatePicker/DatePicker.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/DatePicker/DatePicker.tsx @@ -67,7 +67,6 @@ export const getStyles = (theme: GrafanaTheme2) => { return { modal: css({ zIndex: theme.zIndex.modal, - position: 'absolute', boxShadow: theme.shadows.z3, backgroundColor: theme.colors.background.primary, border: `1px solid ${theme.colors.border.weak}`, diff --git a/packages/grafana-ui/src/components/DateTimePickers/DatePickerWithInput/DatePickerWithInput.tsx b/packages/grafana-ui/src/components/DateTimePickers/DatePickerWithInput/DatePickerWithInput.tsx index 581d6b72e96..69933e8d645 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/DatePickerWithInput/DatePickerWithInput.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/DatePickerWithInput/DatePickerWithInput.tsx @@ -1,5 +1,6 @@ import { css } from '@emotion/css'; -import React, { ChangeEvent } from 'react'; +import { autoUpdate, flip, shift, useClick, useDismiss, useFloating, useInteractions } from '@floating-ui/react'; +import React, { ChangeEvent, useState } from 'react'; import { dateTime } from '@grafana/data'; @@ -35,17 +36,41 @@ export const DatePickerWithInput = ({ placeholder = 'Date', ...rest }: DatePickerWithInputProps) => { - const [open, setOpen] = React.useState(false); + const [open, setOpen] = useState(false); const styles = useStyles2(getStyles); + // the order of middleware is important! + // see https://floating-ui.com/docs/arrow#order + const middleware = [ + flip({ + // see https://floating-ui.com/docs/flip#combining-with-shift + crossAxis: false, + boundary: document.body, + }), + shift(), + ]; + + const { context, refs, floatingStyles } = useFloating({ + open, + placement: 'bottom-start', + onOpenChange: setOpen, + middleware, + whileElementsMounted: autoUpdate, + strategy: 'fixed', + }); + + const click = useClick(context); + const dismiss = useDismiss(context); + const { getReferenceProps, getFloatingProps } = useInteractions([dismiss, click]); + return (
setOpen(true)} onChange={(ev: ChangeEvent) => { // Allow resetting the date if (ev.target.value === '') { @@ -54,20 +79,23 @@ export const DatePickerWithInput = ({ }} className={styles.input} {...rest} + {...getReferenceProps()} /> - { - onChange(ev); - if (closeOnSelect) { - setOpen(false); - } - }} - onClose={() => setOpen(false)} - /> +
+ { + onChange(ev); + if (closeOnSelect) { + setOpen(false); + } + }} + onClose={() => setOpen(false)} + /> +
); }; @@ -84,5 +112,8 @@ const getStyles = () => { WebkitAppearance: 'none', }, }), + popover: css({ + zIndex: 1, + }), }; }; diff --git a/public/app/features/serviceaccounts/components/CreateTokenModal.tsx b/public/app/features/serviceaccounts/components/CreateTokenModal.tsx index a86e578c277..92484a0cdbd 100644 --- a/public/app/features/serviceaccounts/components/CreateTokenModal.tsx +++ b/public/app/features/serviceaccounts/components/CreateTokenModal.tsx @@ -84,13 +84,7 @@ export const CreateTokenModal = ({ isOpen, token, serviceAccountLogin, onCreateT const modalTitle = !token ? 'Add service account token' : 'Service account token created'; return ( - + {!token ? (
{ const getStyles = (theme: GrafanaTheme2) => { return { - modal: css` - width: 550px; - `, - modalContent: css` - overflow: visible; - `, - modalTokenRow: css` - display: flex; - `, - modalCopyToClipboardButton: css` - margin-left: ${theme.spacing(0.5)}; - `, + modal: css({ + width: '550px', + }), + modalTokenRow: css({ + display: 'flex', + }), + modalCopyToClipboardButton: css({ + marginLeft: theme.spacing(0.5), + }), }; };