Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start with left menu collapsed

Tags:

react-admin

Is there an easy was to start with the left menu collapsed or do I need to update the layout ? I'd like to have the menu collapsed by default with only the icons visible. Thank you.

like image 442
Christophe Avatar asked Dec 13 '22 11:12

Christophe


1 Answers

If you mean Sidebar when saying "left menu", you can hide it by turning on the user saga (the toggle action will continue to work):

// closeSidebarSaga.js

import {
  put,
  takeEvery,
} from 'redux-saga/effects'

import {
  REGISTER_RESOURCE, // React-admin 3.5.0 
  setSidebarVisibility,
} from 'react-admin'

function* closeSidebar(action) {
  try {
    if (action.payload) {
      yield put(setSidebarVisibility(false))
    }
  } catch (error) {
    console.log('closeSidebar:', error)
  }
}

function* closeSidebarSaga() {
  yield takeEvery(REGISTER_RESOURCE, closeSidebar) 
}

export default closeSidebarSaga

// App.js:

import closeSidebarSaga from './closeSidebarSaga'

<Admin customSagas={[ closeSidebarSaga ]} ... }>
...
</Admin>

In the react-admin library itself, apparently a bug, at some point in time after the login, action SET_SIDEBAR_VISIBILITY = true is called!

like image 134
MaxAlex Avatar answered Feb 28 '23 10:02

MaxAlex