Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Next Tab Button for dcc.Tabs #786

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Conversation

HammadTheOne
Copy link
Collaborator

@HammadTheOne HammadTheOne commented Apr 6, 2020

This PR addresses #685 and adds a next tab button to sequentially scroll through tabs within dcc.Tabs. In it's current implementation, the next_tab prop of dcc.Tabs is a bool which determines whether or not it is added to the component.

To Do:

  • Add Basic Integration Test.
  • Support for next tab specific styling.
  • Add changelog entry.

Added a next_tab_layout prop. This is a object/dict which (hopefully) mimics the Plotly graphs styling, where title modifies the text of the button, and style is a object/dict which overrides the default styling of the tab and allows the next-tab button to have separate styling from the rest of the component.

Closes #685

Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HammadTheOne This is looking good. Lots of coding suggestions and suggestions for updating the next_tab props based on previous discussion during demo.

Also, since it's the exact opposite functionality, I think we should also add Previous as part of this PR.

className={tabClassName}
id="next-tab"
style={tabStyle}
onClick={() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the useCallback hook instead so as to not create a new function for this callback each time the component is rendered.

@@ -121,6 +121,96 @@ EnhancedTab.defaultProps = {
},
};

const NextTab = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider wrapping in React.memo to make this component Pure.
https://reactjs.org/docs/react-api.html#reactmemo

@@ -121,6 +121,96 @@ EnhancedTab.defaultProps = {
},
};

const NextTab = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is becoming very big. Consider breaking up the Tabs component file into multiple files. One way to do this would be to rename src/components/Tabs.react.js to src/components/Tabs.react/index.js (existing imports will recognize <folder>/index.js as the same as <folder>.js and won't require changes) and moving EnhancedTabs and NextTab into files of their own, referenced here.

@@ -229,6 +320,69 @@ export default class Tabs extends Component {
});
}

if (this.props.children) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -168,6 +258,7 @@ export default class Tabs extends Component {
render() {
let EnhancedTabs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a change from this PR, but consider renaming to enhancedTabs - Pascal-Casing for variables deviates from the norm.

persisted_props: ['value'],
persistence_type: 'local',
next_tab_layout: {title: 'Next', style: null},
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next_tab and next_tab_layout could be combined into a single navigation prop that would be extensible in the future. For example:

navigation: PropTypes.object({
  next: PropTypes.oneOf([
    PropTypes.bool,
    PropTypes.object({
      title: PropTypes.string,
      style: PropTypes.object
    })
  ])
})

Would default to false as implemented.

Using true would default to

{ title: 'Next', style: undefined }

Defining title, style would combine/override the defaults above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later we can add Previous, Last, First, Hide Tabs, etc. to suit our needs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of title, let's do label so that it matches dcc.Tab (

/**
* The tab's label
*/
label: PropTypes.string,
)

@@ -229,6 +320,69 @@ export default class Tabs extends Component {
});
}

if (this.props.children) {
nextTab = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a function, just create the instance of NextTab here directly


dash_dcc.wait_for_element('#next-tab').click()

dash_dcc.wait_for_text_to_equal("#tabs-output", "tab-2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to see another test case without child tabs that makes sure Next is not present.

(loading_state && loading_state.is_loading) || undefined
}
className={tabClassName}
id="next-tab"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component fragment can't have a constant id. If there are multiple dcc.Tabs in the page, they will clash. You could use the component's id and append something to it like ${id}-next-tab.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, EnhancedTab uses the child component's id, which should not be duplicated.
https://github.com/plotly/dash-core-components/pull/786/files#diff-87a94af645034b5ac219cbbfb96a6295R301

}}
>
<span>{title}</span>
<style jsx>{`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"next" button on tabs?
3 participants