diff --git a/vizro-core/examples/default/app.py b/vizro-core/examples/default/app.py index bb0ada9f2..547a718e6 100644 --- a/vizro-core/examples/default/app.py +++ b/vizro-core/examples/default/app.py @@ -527,12 +527,14 @@ def create_home_page(): selector=vm.NavBar( items=[ vm.NavItem( + text="asdf", pages={ "Analysis": ["Homepage", "Variable Analysis"], "Summary": ["Relationship Analysis", "Continent Summary"], }, ), vm.NavItem( + text="ASDF", pages=["Country Analysis"], icon="summarize", ), diff --git a/vizro-core/src/vizro/models/_navigation/accordion.py b/vizro-core/src/vizro/models/_navigation/accordion.py index fc3b3b58a..2d4606be7 100644 --- a/vizro-core/src/vizro/models/_navigation/accordion.py +++ b/vizro-core/src/vizro/models/_navigation/accordion.py @@ -23,7 +23,7 @@ class Accordion(VizroBaseModel): """ type: Literal["accordion"] = "accordion" - pages: Optional[Dict[str, List[str]]] = Field( + pages: Dict[str, List[str]] = Field( {}, description="A dictionary with a page group title as key and a list of page IDs as values." ) diff --git a/vizro-core/src/vizro/models/_navigation/nav_bar.py b/vizro-core/src/vizro/models/_navigation/nav_bar.py index 5b2a15164..247a2686f 100644 --- a/vizro-core/src/vizro/models/_navigation/nav_bar.py +++ b/vizro-core/src/vizro/models/_navigation/nav_bar.py @@ -24,10 +24,10 @@ class NavBar(VizroBaseModel): """ type: Literal["navbar"] = "navbar" # AM: nav_bar? - pages: Optional[Dict[str, List[str]]] = Field( + pages: Dict[str, List[str]] = Field( {}, description="A dictionary with a page group title as key and a list of page IDs as values." ) - items: Optional[List[NavItem]] = [] # AM: think about name + items: List[NavItem] = [] # AM: think about name # validators _validate_pages = validator("pages", allow_reuse=True)(_validate_pages) diff --git a/vizro-core/src/vizro/models/_navigation/nav_item.py b/vizro-core/src/vizro/models/_navigation/nav_item.py index 92cfc3c59..e5d41d235 100644 --- a/vizro-core/src/vizro/models/_navigation/nav_item.py +++ b/vizro-core/src/vizro/models/_navigation/nav_item.py @@ -29,7 +29,7 @@ class NavItem(VizroBaseModel): """ type: Literal["navitem"] = "navitem" # AM: nav_item? - pages: Optional[NavPagesType] = [] + pages: NavPagesType = [] text: str = Field( ..., description="Text to be displayed below the icon." ) # AM: Maybe call label. This just does tooltip for now. diff --git a/vizro-core/src/vizro/models/_navigation/navigation.py b/vizro-core/src/vizro/models/_navigation/navigation.py index f1ccc3c98..444efaab4 100644 --- a/vizro-core/src/vizro/models/_navigation/navigation.py +++ b/vizro-core/src/vizro/models/_navigation/navigation.py @@ -23,8 +23,8 @@ class Navigation(VizroBaseModel): Defaults to `None`. """ - pages: Optional[NavPagesType] = None # AM: yes but NavPagesType: note breaking change, maybe put whole type hint in - selector: Optional[NavSelectorType] = None + pages: NavPagesType = [] # AM: yes but NavPagesType: note breaking change, maybe put whole type hint in + selector: NavSelectorType = Accordion() # validators _validate_pages = validator("pages", allow_reuse=True)(_validate_pages) @@ -33,7 +33,6 @@ class Navigation(VizroBaseModel): def pre_build(self): # Since models instantiated in pre_build do not themselves have pre_build called on them, we call it manually # here. Note that not all selectors have pre_build (Accordion does not). - self.selector = self.selector or Accordion() self.selector.pages = self.selector.pages or self.pages if hasattr(self.selector, "pre_build"): self.selector.pre_build()