Skip to content

Commit

Permalink
add demo mode (__demoMode) (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Feb 21, 2022
1 parent ead5ff8 commit 12ddee8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Expand Up @@ -234,10 +234,11 @@ let ComboboxRoot = forwardRefWithAs(function Combobox<
value: TType
onChange(value: TType): void
disabled?: boolean
__demoMode?: boolean
},
ref: Ref<TTag>
) {
let { value, onChange, disabled = false, ...passThroughProps } = props
let { value, onChange, disabled = false, __demoMode = false, ...passThroughProps } = props

let comboboxPropsRef = useRef<StateDefinition['comboboxPropsRef']['current']>({
value,
Expand All @@ -252,7 +253,7 @@ let ComboboxRoot = forwardRefWithAs(function Combobox<
})

let reducerBag = useReducer(stateReducer, {
comboboxState: ComboboxStates.Closed,
comboboxState: __demoMode ? ComboboxStates.Open : ComboboxStates.Closed,
comboboxPropsRef,
optionsPropsRef,
inputPropsRef,
Expand Down
5 changes: 3 additions & 2 deletions packages/@headlessui-react/src/components/dialog/dialog.tsx
Expand Up @@ -112,10 +112,11 @@ let DialogRoot = forwardRefWithAs(function Dialog<
open?: boolean
onClose(value: boolean): void
initialFocus?: MutableRefObject<HTMLElement | null>
__demoMode?: boolean
},
ref: Ref<HTMLDivElement>
) {
let { open, onClose, initialFocus, ...rest } = props
let { open, onClose, initialFocus, __demoMode = false, ...rest } = props
let [nestedDialogCount, setNestedDialogCount] = useState(0)

let usesOpenClosedState = useOpenClosed()
Expand Down Expand Up @@ -185,7 +186,7 @@ let DialogRoot = forwardRefWithAs(function Dialog<
)

let ready = useServerHandoffComplete()
let enabled = ready && dialogState === DialogStates.Open
let enabled = ready ? (__demoMode ? false : dialogState === DialogStates.Open) : false
let hasNestedDialogs = nestedDialogCount > 1 // 1 is the current dialog
let hasParentDialog = useContext(DialogContext) !== null

Expand Down

0 comments on commit 12ddee8

Please sign in to comment.