Looking to keep the buttons within a Vue component fixed in place for easy switching?

I've implemented a Vue component called UserAuthentication that can switch between the signin and signup components. The component contains buttons for switching between signing in and signing up, which I want to be fixed on top of the form-box from both signin.vue and signup.vue.

The signin.vue and signup.vue components are identical except for additional fields in signup.vue:


<div class="container">
    <div class="form-box">
        <h1 ref="title">Sign In</h1>

            <form @submit.prevent="handleSubmit"> 
                <div class="input-group">

                    <div class="input-field">
                        <input type="email" v-model="email" placeholder="Email"> 
                    </div>

                    <div class="input-field">
                        <input type="password" v-model="password" placeholder="Password"> 
                    </div>
                    
                </div>
                <div class="btn-field">
                    <button class="invert" id="signupBtn" @click="signUp = !signUp">Sign In</button>
                </div>
            </form>
    </div>
</div>

UserAuthenticaion.vue

<template>
  <div class="user-authentication">
    <div class="auth-container">
      <div class="button-field">
        <button class="b1" @click="showSignIn">Sign-in</button>
        <button class="b2" @click="showSignUp">Sign-up</button>
      </div>
      <!-- Conditional rendering of components -->
      <SignIn v-if="currentComponent === 'sign-in'" class="sign-in"></SignIn>
      <SignUp v-else-if="currentComponent === 'sign-up'" class="sign-up">
        <div class="container">
          <div class="form-box">
            <!-- Content from SignUp.vue -->
            <!-- ... -->
          </div>
        </div>
      </SignUp>
    </div>
  </div>
</template>

<script>
import SignIn from './signIn.vue';
import SignUp from './signUp.vue';

export default {
  name: 'UserAuthentication',
  components: {
    SignIn,
    SignUp,
  },
  data() {
    return {
      currentComponent: 'sign-up',
    };
  },
  methods: {
    showSignIn() {
      this.currentComponent = 'sign-in';
    },
    showSignUp() {
      this.currentComponent = 'sign-up';
    },
  },
};
</script>

<style scoped>
/* Existing styles for user-authentication */
/* ... */

.auth-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column; /* Ensure vertical layout */
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
  z-index: 999; /* Ensure the container is on top */
}

.button-field {
  position: fixed;
  top: 90px; /* Adjust the top position as needed */
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: 200px; /* Set a specific width for the button container */
}

.sign-up .container {
  position: relative;
  padding-top: 50px; /* Space for the fixed button-field */
}

.sign-up .form-box {
  /* Other styles */
}
</style>

Answer №1

Check out the revised UserAuthentication.vue component below

<template>
  <div class="user-authentication">
    <div class="auth-container">
      <div class="button-field">
        <button class="b1" @click="showSignIn">Log in</button>
        <button class="b2" @click="showSignUp">Sign up</button>
      </div>
      <div class="form-container">
        <LogIn v-if="currentComponent === 'log-in'"></LogIn>
        <SignUp v-else-if="currentComponent === 'sign-up'"></SignUp>
      </div>
    </div>
  </div>
</template>

<script>
import LogIn from './login.vue';
import SignUp from './signup.vue';

export default {
  name: 'UserAuthentication',
  components: {
    LogIn,
    SignUp,
  },
  data() {
    return {
      currentComponent: 'sign-up',
    };
  },
  methods: {
    showSignIn() {
      this.currentComponent = 'log-in';
    },
    showSignUp() {
      this.currentComponent = 'sign-up';
    },
  },
};
</script>

<style scoped>
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 100%;
}

.button-field {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: 100%;
  background-color: white;
  display: flex;
  justify-content: center;
  padding: 10px 0;
}

.form-container {
  width: 100%;
  margin-top: 60px;
}
</style>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Testing an API request using Jasmine for unit testing

I am currently working on writing unit tests for the website I'm developing at my job. One thing I'm struggling with is how to effectively test an API call within one of my Vue components. Let's say I have the following code snippet in my V ...

How to make a 3D rounded corner cube using Three.js

Can a customized cube with rounded edges be constructed using three.js and subsequently textured with an image? ...

I am having difficulty organizing my text into two grid columns and aligning it in the center

.hero { display: grid; grid-template-columns: repeat(2, 33.45rem); grid-template-rows: 12.5rem; border-bottom: .05em solid #05d31f; width: 69.8rem; height: 16.5rem; } .hero-title { grid-row-start: 1; grid-column-start: 1; } .hero-title h ...

Enhance your React application by making two API requests in

Below is the React Component that I am working on: export default function Header () { const { isSessionActive, isMenuOpen, isProfileMenuOpen, setIsMenuOpen, closeMenu, URL } = useContext(AppContext) const [profileData, setProfileData] = useState({}) ...

What is the best way to execute NPM commands within the terminal of Visual Studio Code?

I recently installed npm in VSCode from extensions, but I am having trouble activating it. When I try to run the command 'npm init' in the terminal, I receive the following error message: "The term 'npm' is not recognized as the name of ...

Encountering issues with NuxtJs development build after upgrading to version 2.15

After updating my old nuxtjs project from version 1.4.5 to 2.12.0, I encountered an issue during the client bundle building process. The error message I received was: ERROR Failed to compile with 1 errors ...

"Double the Data: A D3.js JSON Tale of Two Creators

I found inspiration from this example: http://bl.ocks.org/mbostock/1062288 to create a collapsible Force Layout. One challenge I'm facing is how to display a graph where a single node is connected to two parent nodes. father father | | ...

Guide to creating JSDoc for a TouchEvent handler

Looking to improve my shorter-js codebase with JSDoc for TypeScript definitions, but hitting a roadblock. I've implemented the on() function using Element.addEventListener, working well so far. However, when passing a TouchEvent as a parameter for an ...

Sort your list efficiently with a custom hook in React using Typescript

I've been working on developing a custom hook in React that sorts an array based on two arguments: the list itself and a string representing the key to sort by. Despite trying various approaches, I haven't been able to find a solution yet. I&apos ...

Is the Bootstrap navigation bar collapse button visible on larger screens?

How can I make my Bootstrap navbar collapse button work on big screens the same way it does on mobile devices? <nav class="navbar navbar-expand-md navbar-light bg-light"> <a class="navbar-brand" href="#">Default</a> <button ...

What is the best way to position an icon to the left of the text?

My code is as follows: <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <span> <i class="fa fa-check"></i> This text is just a test and repeating to ...

How can we properly access the DOM element generated by an {#each} loop in Svelte when it is clicked?

Using Svelte's {#each} functionality, I am reactively loading elements in the following way: {#each $items as item} <div> <Button on:click={someFunction}>{item.text}</Button> (*) </div> {/each} (*) a component t ...

Avoid triggering the resizecolumn event in ExtJS while the columns are still loading

Currently, I am involved in a project using ExtJS 6.2 and facing a challenge related to performing operations when the columns in a grid are resized. It seems like the suitable event for this task is columnresize. However, the issue arises because the colu ...

What could be causing my component to fail to load properly with Vite?

I have been working on a React project using Vite. Following a tutorial I discovered in an article at https://www.digitalocean.com/community/tutorials/how-to-set-up-a-react-project-with-vite, I encountered an issue. Despite following the tutorial step by ...

Receiving files in Javascript from Flask using the send_file() function is a common task that many developers

I am in the process of creating a web application that utilizes HTML along with plain Javascript for the frontend, and Flask as the backend. The main function of the application is to send an ID to the server, where it will then generate a PDF report and s ...

The two-word string is failing to pass through the query string

I've been working on passing multiple values through the query string. So far, I have successfully passed single-word values to a PHP page using jQuery. However, I encountered an issue when trying to pass a user's name like "Vishal Deb" as it onl ...

How can you configure fancybox3 to open exclusively on a double-click?

Looking for a solution to open a fancybox gallery with a double click on a grid of sortable images. The goal is to be able to focus on an image with a single click, allowing for sorting using keyboard commands rather than drag and drop. I attempted to use ...

View unprocessed HTML content - Angular 6

I want to showcase the raw HTML code (example.component.html) below 'example works!'. The page should display as follows: example works! <p> example works! </p> While there are resources available on how to do this with Ang ...

The $resource.query function will now return an array of characters instead of a single string when splitting strings

Recently, I've been working on utilizing an Angular $resource in my project. Here's a snippet of the code: angular.module('app') .factory('data', function ($resource) { var Con = $resource('/api/data', {}, { ...

Error in Node.js: The res.send method is undefined

I'm having some issues with my first attempt at creating a simple Counter Strike API bot using nodeJS. The problem lies with the res.send function, as I keep getting an error message saying "res.send is not a function" every time I try to use it. Movi ...