How to use the fixed menu and sidebar of semantic-ui in React

Source: Internet
Author: User



Semantic-ui's fixed menu and sidebar are well run in body (this is Sui's default design), but in react applications, the component system is placed in a relatively deep place, it is difficult to put directly in the body, at this time, a lot of problems.



Basic idea: Create a sidebar component as the context for the sidebar and put the content in the Pusher section.



In so doing, you will find a lot of problems: NavBar and sidebar are no longer fixed, display problems, scrolling problems ...



The reason for this is that the CSS3 transform attribute is used, which causes the fixed element to fail. After some exploration, there is an imperfect but passable solution.



First, build the sidebar component


<div ref= "Context" classname= "pushable patch" >
    <div ref= "sidebar" classname= "UI Sidebar inverted vertical left menu patch" >
       ...
    </div>
    <div classname= "Pusher" >
        {Children}
    </div>
</div>


Note the. Patch class is added for later repair



Then, initialize the sidebar in the Componentdidmount


$(this.refs.sidebar).sidebar({
    context: $(this.refs.context),
    transition: ‘overlay‘,
    mobileTransition: ‘overlay‘ });


Note that we specify the context and use overlay as the transition to avoid using the Transform property, which is a big limitation.



Then, hit the CSS patch


 
.pushable:not(body).patch { -webkit-transform: unset; transform: unset;
} .pushable:not(body) .patch.ui.sidebar { position: fixed;
}


First, remove the transform setting from the context, and then fix the sidebar position. Done.



This article is just a discussion, and the great God who has also faced this problem can share more excellent solutions.



How to use the fixed menu and sidebar of semantic-ui in React


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.