Looking for a way to add a permanent footer to the bottom of your webpage without affecting the tab order for accessibility?

I have a paginated form with a fixed navigation footer at the bottom that needs to stay in place even when scrolling. This footer should also be at the bottom of the page for mobile devices and tablets.

To achieve this, I used position: fixed on the footer element.

However, I encountered an issue with keyboard and tab navigation accessibility. After clicking the "Next" button and pressing the tab key, instead of shifting focus to the next element on the page, it navigates to tabs in the browser like bookmarks.

When I removed the position: fixed, the footer no longer stays at the bottom but the tab navigation works correctly.

I created a sandbox demonstrating the functionality:

https://codesandbox.io/s/exciting-lumiere-05y7o7?file=/src/styles.css

Is there a way to ensure tab navigation moves to the next focusable element after clicking "Next page" or maintain the footer at the bottom without using position: fixed or position: absolute?

const Page1Component = () => {
  return (
    <div>
      <h1>Page 1</h1>
      <input type="text" placeholder="Textbox 1" />
    </div>
  );
};

const Page2Component = () => {
  return (
    <div>
      <h1>Page 2</h1>
      <input type="text" placeholder="Textbox 2" />
    </div>
  );
};

const Page3Component = () => {
  return (
    <div>
      <h1>Page 3</h1>
      <textarea></textarea>
    </div>
  );
};

const PaginatedForm = () => {
  const [page, setPage] = React.useState(1);
  const renderPage = () => {
    if (page === 1) return <Page1Component />;
    if (page === 2) return <Page2Component />;
    if (page === 3) return <Page3Component />;
  };

  return (
    <main>
      <header>My Header</header>
      <div className="wrapper">{renderPage()}</div>
      <footer>
        <button onClick={() => setPage(page + 1)}>Next page</button>
      </footer>
    </main>
  );
};

// Render it
ReactDOM.render(
    <PaginatedForm />,
    document.getElementById("root")
);
html,
body {
  padding: 0;
  margin: 0;
}

header {
  background-color: lightblue;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper {
  background-color: goldenrod;
  height: calc(100vh - 30px);
  overflow-y: auto;
}

footer {
  display: flex;
  justify-content: right;
  background-color: firebrick;
  height: 30px;

  position: fixed; /* Removing these last three styles fixes the tabbing issue*/
  width: 100%;
  bottom: 0;
}
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>

Answer №1

After investigating, I've determined that the issue stems from a CSS problem rather than React. The solution was to adjust the styling using display: grid on the main tag in order to create a 3-row layout. The first row contains the header, set with a height of auto to only take up necessary space. The second row is for content and set with 1fr to occupy all available space. Finally, the footer utilizes auto as well to dynamically adjust its height. To ensure the footer always stays at the bottom, I specified a min-height: 100vh for the main element to fill the entire screen height. Below is the updated CSS:

main {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

header {
  background-color: lightblue;
  height: 30px;
}

.wrapper {
  background-color: goldenrod;
}

footer {
  display: flex;
  justify-content: right;

  background-color: firebrick;
  height: 30px;
}

If you're concerned about changes being saved on CodeSandbox, you can check here: https://codesandbox.io/s/quirky-cdn-vtxkec?file=/src/styles.css

For applications with multiple routes, it's advisable to create a dedicated layout component to ensure that the content remains within the main section.

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

Spin the object at regular intervals

Recently, I stumbled upon this interactive Pen: https://codepen.io/golle404/pen/BoqrEN that caught my eye. I thought it would be interesting to make the object move every few seconds. My first attempt involved using the following code snippet: setTimeout( ...

What is a sneaky way to conceal CSS specifically from iPhones without affecting other browsers?

I have a solution to conceal CSS from all browsers except for iPhones. You can find the details here: How do I apply a stylesheet just to the iPhone (and not IE), without browser sniffing? Now, my question is: How can I hide CSS specifically from iPhones ...

A guide on displaying a text file from a URL in a reactjs application

When utilizing the code provided below, I have successfully managed to display the content of a local text file on a webpage. However, when attempting to render a text file from a URL, the state becomes null resulting in an empty display. In order to ren ...

Embarking on the journey of creating mobile web applications - where should you begin?

How can I begin learning to create mobile web apps? I have a keen interest in the design aspects, particularly the effects and animations that give them a native appearance. I suspect there are differences in CSS, HTML, and possibly JavaScript compared to ...

Sending information from a child array to the parent array

Passing data to a Parent useState was pretty straightforward when the child component was not in an array. However, now that the child component is in an Array, it throws an error - "sendData is not a function." I have created a sandbox to demonstrate the ...

Animating an image in an HTML document by clicking a button through jQuery

I am trying to figure out how to make an image move from the left to the right of a page when a button is clicked. I thought the code below would work, but unfortunately, it's not functioning as expected. I'm new to JQuery and could use some guid ...

Express route not capturing entire request parameter due to regex issue

I am pretty sure that the issue lies in how express handles regex patterns in route definitions, although it might also be related to my pattern (I'm still new to regex, so please bear with me). In my express route definition, I am attempting to match ...

What are some creative ways to format text displayed using ngx-markdown?

I'm currently in the process of building a blog using Angular and I have decided to use Markdown for creating my posts. Specifically, I am looking into integrating ngx-markdown for rendering purposes. As of now, I am developing a component dedicated t ...

Deliver an extensive JSON reply through a Node.js Express API

When dealing with a controller in a node/express API that generates large data sets for reports, reaching sizes as big as 20Mb per request, maintaining a positive user experience becomes essential. What strategies can be employed to efficiently handle suc ...

Adding Firebase Authentication to my AngularJS website

I am currently creating a school website using AngularJS. My goal is to incorporate account functionality through firebase authentication. However, I have limited experience with Javascript and find working with AngularJS and implementing firebase to be ...

Universal PM2 Configuration Settings in JSON Format

My current process involves initiating numerous Node.js processes using pm2. These processes are configured in a JSON file and started by executing pm2 start pm2.json Upon examining the JSON file provided below, it's evident that there is significan ...

Align text vertically within a link box by overriding inherited CSS styles

Fiddle: http://jsfiddle.net/jgallaway81/ax9wh/ <a href="lcars.jfx.php" class="leftbuttons buttonlinks antibutton"> LCARS Locomotive O.S. </a> My issue pertains to the alignment of text within a graphic. I am utilizing this particular button ...

Basic asynchronous JavaScript and XML (AJAX) call

I am currently learning about ajax and experimenting with a script that involves extracting information from a JSON object and displaying it on the document. Below is an example of the JSON file named companyinfo.json: { 'id':1, 'name&apos ...

Unable to simulate the Enter key press event for a text area using Angular 7

I've implemented a feature that allows users to type something and then press the submit button, at which point the cursor should move to the next line. If the user types some words and presses the Enter key, the cursor should also shift to the next l ...

What exactly does Container-Based Authorization entail?

Did you know that the "XMLHttpRequest" object includes a method called "open," which has the option to supply a username and password? These parameters can be used for requests that require container-based authentication. Here is the method signature: op ...

Showing HTML element when the model count is zero - ASP.NET MVC View

My view has a dynamic element that switches between two options depending on the Model.Count property. Check out the code below: @if (Model.Count() == 0) { <div class="well well-lg"><h3>Everyone is present! No absences today :)</h3>& ...

placing additional containers at the bottom rather than on the right side

Hey there! I'm currently working on a simple website and I'm having trouble getting the duplicated form rows to appear aligned below the previous one. Here's what I have right now: var i = 0; var original = document.getElementById("dupl ...

Is it possible for you to execute 2 procedures consecutively simply by clicking on a button?

My question is quite straightforward. I have two buttons: <button @click="getPartyLeader" class="btn btn-success">Get party leader</button> <button @click="saveParty" class="btn btn-success">Submi ...

Tips for importing the identical glTF model in both Three.js and React-Three-Fiber

For my project using react-three-fiber, I am working on creating a 3D house. I decided to incorporate GLTF models for the doors in the house. Initially, rendering one door worked perfectly fine. However, when I attempted to render two doors from the same ...

Issue with border in a nested table within an HTML table

I am faced with an issue in styling nested tables. My goal is to have borders on both tables, but I specifically need only the bottom border of the inner table without the top, right, and left borders. The default border style can be achieved using the fol ...