Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic window title #5893

Open
jtomaszewski opened this issue Feb 10, 2021 · 11 comments
Open

Dynamic window title #5893

jtomaszewski opened this issue Feb 10, 2021 · 11 comments

Comments

@jtomaszewski
Copy link
Contributor

jtomaszewski commented Feb 10, 2021

Currently all our admin app browser tabs are named in the same way; and the names in the browser history aren't really helpful neither:

image

Maybe we could add some useEffect code to https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/layout/Title.tsx that updates the document.title whenever new title is set? WDYT?

@MicroJackson
Copy link

How I do it with my React Admin:

class SettingsList extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        document.title = "Some new document title.";
    }

    ......

And it shows that in the history and as the title.
But maybe a MaterialUI update version is better.

@djhi
Copy link
Collaborator

djhi commented Feb 11, 2021

@jtomaszewski Thanks for the suggestion! Would you mind creating a PR for it?

@andrico1234
Copy link
Contributor

Is someone currently working on this? If not, I'd be happy to give it a shot

@andrico1234
Copy link
Contributor

andrico1234 commented Apr 2, 2021

@djhi I got carried away 😅

#6118

@fzaninotto
Copy link
Member

Fixed by #6119

@andrico1234
Copy link
Contributor

@fzaninotto can we re-open this issue as the change was reverted. I'm going to give @wmwart's suggestion,

@fzaninotto
Copy link
Member

Yep, the fix was reverted in #6357, so I'm reopening it.

@panfiva
Copy link

panfiva commented Feb 1, 2022

FYI, users can customize browser page title using react-helmet. See example code that can be placed in Show, Edit, List or Create components.

  <Helmet>
      <title>New page title</title>
  </Helmet>

@btoro
Copy link

btoro commented Sep 14, 2022

FYI, users can customize browser page title using react-helmet. See example code that can be placed in Show, Edit, List or Create components.

  <Helmet>
      <title>New page title</title>
  </Helmet>

Ideally, the <Title/> component would automatically sent the title over to Helmet, rather than having users add the title to each page / view.

You can use react portals to inject the title into the <title> component of react-helmet, but unfortunately, RA adds an additional around the text, which messes up the header title.

It would be great if we can override the Title component as part of the customization / layout

@lefuturiste
Copy link

@fzaninotto I'm interested to work on this issue. Before opening a new PR, I will discuss the details here.
For a start, I propose to make this feature an opt-in change. So by default it keep the same behavior as before.
So probably we should add a new boolean prop, eg. mirrorTitleToDocumentTitle={true}

@fzaninotto
Copy link
Member

React 19 introduces the <title> tag that does exactly that. If we can use if in a backward-compatible way (i.e. without breaking apps using React 18), it's the best solution. We could simply update PageTitle to set <title>in addition to the TitlePortal.

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

Successfully merging a pull request may close this issue.

8 participants