2019-04-16 11:22:05 -04:00
# Frontend FAQ
## Rules of Frontend FAQ
1. **You talk about Frontend FAQ.**
Please share links to it whenever applicable, so more eyes catch when content
gets outdated.
2019-07-18 22:20:32 -04:00
1. **Keep it short and simple.**
2019-04-16 11:22:05 -04:00
Whenever an answer needs more than two sentences it does not belong here.
2019-07-18 22:20:32 -04:00
1. **Provide background when possible.**
2019-04-16 11:22:05 -04:00
Linking to relevant source code, issue / epic, or other documentation helps
to understand the answer.
2019-07-18 22:20:32 -04:00
1. **If you see something, do something.**
2019-04-16 11:22:05 -04:00
Please remove or update any content that is outdated as soon as you see it.
## FAQ
2019-11-19 22:06:28 -05:00
### 1. How do I find the Rails route for a page?
2019-04-16 11:22:05 -04:00
2019-09-18 10:02:45 -04:00
#### Check the 'page' data attribute
2019-04-16 11:22:05 -04:00
The easiest way is to type the following in the browser while on the page in
question:
```javascript
document.body.dataset.page
```
2019-09-18 14:06:14 -04:00
Find here the [source code setting the attribute ](https://gitlab.com/gitlab-org/gitlab/blob/cc5095edfce2b4d4083a4fb1cdc7c0a1898b9921/app/views/layouts/application.html.haml#L4 ).
2019-09-18 10:02:45 -04:00
#### Rails routes
The `rake routes` command can be used to list all the routes available in the application, piping the output into `grep` , we can perform a search through the list of available routes.
The output includes the request types available, route parameters and the relevant controller.
```sh
bundle exec rake routes | grep "issues"
```
2019-06-06 05:36:17 -04:00
2019-11-19 22:06:28 -05:00
### 2. `modal_copy_button` vs `clipboard_button`
2019-06-06 05:36:17 -04:00
The `clipboard_button` uses the `copy_to_clipboard.js` behaviour, which is
initialized on page load, so if there are vue-based clipboard buttons that
don't exist at page load (such as ones in a `GlModal` ), they do not have the
click handlers associated with the clipboard package.
`modal_copy_button` was added that manages an instance of the
[`clipboard` plugin ](https://www.npmjs.com/package/clipboard ) specific to
the instance of that component, which means that clipboard events are
bound on mounting and destroyed when the button is, mitigating the above
issue. It also has bindings to a particular container or modal ID
available, to work with the focus trap created by our GlModal.
2019-11-19 22:06:28 -05:00
2019-12-11 01:07:52 -05:00
### 3. A `gitlab-ui` component not conforming to [Pajamas Design System](https://design.gitlab.com/)
2019-11-19 22:06:28 -05:00
Some [Pajamas Design System ](https://design.gitlab.com/ ) components implemented in
2019-12-11 01:07:52 -05:00
`gitlab-ui` do not conform with the design system specs because they lack some
2019-11-19 22:06:28 -05:00
planned features or are not correctly styled yet. In the Pajamas website, a
banner on top of the component examples indicates that:
> This component does not yet conform to the correct styling defined in our Design
> System. Refer to the Design System documentation when referencing visuals for this
> component.
For example, at the time of writing, this type of warning can be observed for
[all form components ](https://design.gitlab.com/components/forms ). It, however,
doesn't imply that the component should not be used.
GitLab always asks to use `<gl-*>` components whenever a suitable component exists.
It makes codebase unified and more comfortable to maintain/refactor in the future.
Ensure a [Product Designer ](https://about.gitlab.com/company/team/?department=ux-department )
reviews the use of the non-conforming component as part of the MR review. Make a
follow up issue and attach it to the component implementation epic found within the
[Components of Pajamas Design System epic ](https://gitlab.com/groups/gitlab-org/-/epics/973 ).
2020-01-15 10:08:32 -05:00
### 4. My submit form button becomes disabled after submitting
If you are using a submit button inside a form and you attach an `onSubmit` event listener on the form element, [this piece of code ](https://gitlab.com/gitlab-org/gitlab/blob/794c247a910e2759ce9b401356432a38a4535d49/app/assets/javascripts/main.js#L225 ) will add a `disabled` class selector to the submit button when the form is submitted.
To avoid this behavior, add the class `js-no-auto-disable` to the button.