Skip to content

Commit

Permalink
prevent blur
Browse files Browse the repository at this point in the history
  • Loading branch information
bunsenstraat committed Oct 3, 2024
1 parent 1dc1bb1 commit a5a9329
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const MatomoDialog = (props: MatomoDialogProps) => {
okLabel: <FormattedMessage id="remixApp.accept" />,
okFn: handleModalOkClick,
cancelLabel: <FormattedMessage id="remixApp.decline" />,
cancelFn: declineModal
cancelFn: declineModal,
preventBlur: true
})
}
console.log('visible', visible)
Expand Down
6 changes: 4 additions & 2 deletions libs/remix-ui/app/src/lib/remix-app/context/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt
}

const modal = (modalData: AppModal) => {
const { id, title, message, validationFn, okLabel, okFn, cancelLabel, cancelFn, modalType, modalParentClass, defaultValue, hideFn, data } = modalData
const { id, title, message, validationFn, okLabel, okFn, cancelLabel, cancelFn, modalType, modalParentClass, defaultValue, hideFn, data, preventBlur } = modalData
console.log('modalData', modalData)
return new Promise((resolve, reject) => {
dispatch({
type: modalActionTypes.setModal,
Expand All @@ -42,7 +43,8 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt
hideFn,
resolve,
next: onNextFn,
data
data,
preventBlur
}
})
})
Expand Down
3 changes: 2 additions & 1 deletion libs/remix-ui/app/src/lib/remix-app/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export interface AppModal {
hideFn?: () => void,
resolve?: (value?:any) => void,
next?: () => void,
data?: any
data?: any,
preventBlur?: boolean
}

export interface AlertModal {
Expand Down
3 changes: 2 additions & 1 deletion libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda
hideFn: action.payload.hideFn,
resolve: action.payload.resolve,
next: action.payload.next,
data: action.payload.data
data: action.payload.data,
preventBlur: action.payload.preventBlur
}

const modalList: AppModal[] = state.modals.slice()
Expand Down
4 changes: 3 additions & 1 deletion libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare global {
const _paq = (window._paq = window._paq || [])

export const ModalDialog = (props: ModalDialogProps) => {
console.log('ModalDialog', props)
const [state, setState] = useState({
toggleBtn: true
})
Expand All @@ -33,7 +34,7 @@ export const ModalDialog = (props: ModalDialogProps) => {
calledHideFunctionOnce.current = props.hide
modal.current.focus()

if (modal.current) {
if (modal.current && !props.preventBlur) {
modal.current.removeEventListener('blur', handleBlur)
modal.current.addEventListener('blur', handleBlur)
}
Expand All @@ -45,6 +46,7 @@ export const ModalDialog = (props: ModalDialogProps) => {
function handleBlur(e) {
_paq.push(['trackEvent', 'modal', 'blur', JSON.stringify(e), this.id, props.title, e.currentTarget, e.relatedTarget])
console.log('handleBlur', e.currentTarget, e.relatedTarget, this)
console.trace()
if (e.currentTarget && !e.currentTarget.contains(e.relatedTarget)) {
e.stopPropagation()
if (document.activeElement !== this) {
Expand Down
3 changes: 2 additions & 1 deletion libs/remix-ui/modal-dialog/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ export interface ModalDialogProps {
next?: () => void,
data?: any,
okBtnClass?: string,
cancelBtnClass?: string
cancelBtnClass?: string,
preventBlur?: boolean
}

0 comments on commit a5a9329

Please sign in to comment.