Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to customize FullscreenControl's tooltips #8076

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/ui/control/fullscreen_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import window from '../../util/window';
import type Map from '../map';

type Options = {
container?: HTMLElement
container?: HTMLElement,
tooltipEnter?: string,
tooltipExit?: string
};

/**
Expand All @@ -17,6 +19,8 @@ type Options = {
* @implements {IControl}
* @param {Object} [options]
* @param {HTMLElement} [options.container] `container` is the [compatible DOM element](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#Compatible_elements) which should be made full screen. By default, the map container element will be made full screen.
* @param {string} [options.tooltipEnter] A string to use as a tooltip when the map is not in fullscreen mode. If not specified the default value of 'Enter fullscreen' will be used.
* @param {string} [options.tooltipExit] A string to use as a tooltip when the map is in fullscreen mode. If not specified the default value of 'Exit fullscreen' will be used.
*
* @example
* map.addControl(new mapboxgl.FullscreenControl({container: document.querySelector('body')}));
Expand All @@ -31,6 +35,8 @@ class FullscreenControl {
_fullscreenButton: HTMLElement;
_className: string;
_container: HTMLElement;
_tooltipEnter: string;
_tooltipExit: string;

constructor(options: Options) {
this._fullscreen = false;
Expand All @@ -41,6 +47,8 @@ class FullscreenControl {
warnOnce('Full screen control \'container\' must be a DOM element.');
}
}
this._tooltipEnter = options && options.tooltipEnter || "Enter fullscreen";
this._tooltipExit = options && options.tooltipExit || "Exit fullscreen";
bindAll([
'_onClickFullscreen',
'_changeIcon'
Expand Down Expand Up @@ -94,7 +102,7 @@ class FullscreenControl {
}

_updateTitle() {
const title = this._isFullscreen() ? "Exit fullscreen" : "Enter fullscreen";
const title = this._isFullscreen() ? this._tooltipExit : this._tooltipEnter;
this._fullscreenButton.setAttribute("aria-label", title);
this._fullscreenButton.title = title;
}
Expand Down