Panels are overlays that contain supplementary content and are used for complex creation, edit, or management experiences. For example, viewing details about an item in a list or editing settings.
For more details and examples visit the official docs. The R package cannot handle each and every case, so for advanced use cases you need to work using the original docs to achieve the desired result.
Arguments
- ...
Props to pass to the component. The allowed props are listed below in the Details section.
Details
allowTouchBodyScroll
boolean
Allow body scroll on content and overlay on touch devices. Changing after mounting has no effect.className
string
Additional css class to apply to the PanelcloseButtonAriaLabel
string
Aria label on close buttoncomponentId
string
Deprecated property. Serves no function.componentRef
IRefObject<IPanel>
Optional callback to access the IPanel interface. Use this instead of ref for accessing the public methods and properties of the component.customWidth
string
Custom panel width, used only whentype
is set toPanelType.custom
.elementToFocusOnDismiss
HTMLElement
Sets the HTMLElement to focus on when exiting the FocusTrapZone.firstFocusableSelector
string
Indicates the selector for first focusable item. Deprecated, usefocusTrapZoneProps
.focusTrapZoneProps
IFocusTrapZoneProps
Optional props to pass to the FocusTrapZone component to manage focus in the panel.forceFocusInsideTrap
boolean
Indicates whether Panel should force focus inside the focus trap zone. If not explicitly specified, behavior aligns with FocusTrapZone's default behavior. Deprecated, usefocusTrapZoneProps
.hasCloseButton
boolean
Has the close button visible.headerClassName
string
Optional parameter to provider the class name for header textheaderText
string
Header text for the Panel.headerTextProps
React.HTMLAttributes<HTMLDivElement>
The props for header text container.ignoreExternalFocusing
boolean
Indicates if this Panel will ignore keeping track of HTMLElement that activated the Zone. Deprecated, usefocusTrapZoneProps
.isBlocking
boolean
Whether the panel uses a modal overlay or notisFooterAtBottom
boolean
Determines if content should stretch to fill available space putting footer at the bottom of the pageisHiddenOnDismiss
boolean
Whether the panel is hidden on dismiss, instead of destroyed in the DOM. Protects the contents from being destroyed when the panel is dismissed.isLightDismiss
boolean
Whether the panel can be light dismissed.isOpen
boolean
Whether the panel is displayed. If true, will cause panel to stay open even if dismissed. If false, will cause panel to stay hidden. If undefined, will allow the panel to control its own visility through open/dismiss methods.layerProps
ILayerProps
Optional props to pass to the Layer component hosting the panel.onDismiss
(ev?: React.SyntheticEvent<HTMLElement>) => void
A callback function for when the panel is closed, before the animation completes. If the panel should NOT be dismissed based on some keyboard event, then simply call ev.preventDefault() on itonDismissed
() => void
A callback function which is called after the Panel is dismissed and the animation is complete. (If you need to update the Panel'sisOpen
prop in response to a dismiss event, useonDismiss
instead.)onLightDismissClick
() => void
Optional custom function to handle clicks outside the panel in lightdismiss modeonOpen
() => void
A callback function for when the Panel is opened, before the animation completes.onOpened
() => void
A callback function for when the Panel is opened, after the animation completes.onOuterClick
() => void
Optional custom function to handle clicks outside this componentonRenderBody
IRenderFunction<IPanelProps>
Optional custom renderer for body region. Replaces any children passed into the component.onRenderFooter
IRenderFunction<IPanelProps>
Optional custom renderer for footer region. Replaces sticky footer.onRenderFooterContent
IRenderFunction<IPanelProps>
Custom renderer for content in the sticky footeronRenderHeader
IPanelHeaderRenderer
Optional custom renderer for header region. Replaces current titleonRenderNavigation
IRenderFunction<IPanelProps>
Optional custom renderer navigation region. Replaces the region that contains the close button.onRenderNavigationContent
IRenderFunction<IPanelProps>
Optional custom renderer for content in the navigation region. Replaces current close button.overlayProps
IOverlayProps
Optional props to pass to the Overlay component that the panel uses.styles
IStyleFunctionOrObject<IPanelStyleProps, IPanelStyles>
Call to provide customized styling that will layer on top of the variant rules.theme
ITheme
Theme provided by High-Order Component.type
PanelType
Type of the panel.
Best practices
Layout
Use for self-contained experiences where someone doesn’t need to interact with the app view to complete the task.
Consider how the panel and its contained contents will scale across responsive web breakpoints.
Header
Include a close button in the top-right corner.
Lock the title to the top of the panel.
The header can contain a variety of components. Components are stacked under the main title, locked to the top, and push content down.
Content
Title
Titles should explain the panel content in clear, concise, and specific terms.
Keep the length of the title to one line, if possible.
Use sentence-style capitalization—only capitalize the first word. For more info, see
[Capitalization]
in the Microsoft Writing Style Guide.Don’t put a period at the end of the title.
[capitalization]
: https://docs.microsoft.com/style-guide/capitalization
Examples
library(shiny)
library(shiny.fluent)
ui <- function(id) {
ns <- NS(id)
div(
DefaultButton.shinyInput(ns("showPanel"), text = "Open panel"),
reactOutput(ns("reactPanel"))
)
}
server <- function(id) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
isPanelOpen <- reactiveVal(FALSE)
output$reactPanel <- renderReact({
Panel(
headerText = "Sample panel",
isOpen = isPanelOpen(),
"Content goes here.",
onDismiss = JS(paste0(
"function() {",
" Shiny.setInputValue('", ns("hidePanel"), "', Math.random());",
"}"
))
)
})
observeEvent(input$showPanel, isPanelOpen(TRUE))
observeEvent(input$hidePanel, isPanelOpen(FALSE))
})
}
if (interactive()) {
shinyApp(ui("app"), function(input, output) server("app"))
}