Unverified Commit c8680a34 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Remove `visibility: hidden` from the image component (#23278)

This PR removes the `visibility` style property change from next/image. It was previously added in #18195 to fix a bug that when no `src` is set, and that bug is not valid anymore as all images will always have `src` (and a fallback too).

It also fixes the problem that screen readers ignore elements with `visibility: hidden`.

Fixes #23201.

## Bug

- [x] Related issues #23201
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
parent f384cd10
...@@ -295,8 +295,6 @@ export default function Image({ ...@@ -295,8 +295,6 @@ export default function Image({
let sizerStyle: JSX.IntrinsicElements['div']['style'] | undefined let sizerStyle: JSX.IntrinsicElements['div']['style'] | undefined
let sizerSvg: string | undefined let sizerSvg: string | undefined
let imgStyle: ImgElementStyle | undefined = { let imgStyle: ImgElementStyle | undefined = {
visibility: isVisible ? 'inherit' : 'hidden',
position: 'absolute', position: 'absolute',
top: 0, top: 0,
left: 0, left: 0,
......
...@@ -51,23 +51,6 @@ async function getComputed(browser, id, prop) { ...@@ -51,23 +51,6 @@ async function getComputed(browser, id, prop) {
return null return null
} }
async function getComputedStyle(browser, id, prop) {
const val = await browser.eval(
`window.getComputedStyle(document.getElementById('${id}')).${prop}`
)
if (typeof val === 'number') {
return val
}
if (typeof val === 'string') {
const v = parseInt(val, 10)
if (isNaN(v)) {
return val
}
return v
}
return null
}
async function getSrc(browser, id) { async function getSrc(browser, id) {
const src = await browser.elementById(id).getAttribute('src') const src = await browser.elementById(id).getAttribute('src')
if (src) { if (src) {
...@@ -442,44 +425,6 @@ function runTests(mode) { ...@@ -442,44 +425,6 @@ function runTests(mode) {
}) })
} }
it('should correctly inherit the visibilty of the parent component', async () => {
let browser
try {
browser = await webdriver(appPort, '/docs/hidden-parent')
const id = 'hidden-image'
// Wait for image to load:
await check(async () => {
const result = await browser.eval(
`document.getElementById(${JSON.stringify(id)}).naturalWidth`
)
if (result < 1) {
throw new Error('Image not ready')
}
return 'result-correct'
}, /result-correct/)
await waitFor(1000)
const desiredVisibilty = await getComputed(
browser,
id,
'style.visibility'
)
expect(desiredVisibilty).toBe('inherit')
const actualVisibility = await getComputedStyle(browser, id, 'visibility')
expect(actualVisibility).toBe('hidden')
} finally {
if (browser) {
await browser.close()
}
}
})
it('should correctly ignore prose styles', async () => { it('should correctly ignore prose styles', async () => {
let browser let browser
try { try {
......
...@@ -53,23 +53,6 @@ async function getComputed(browser, id, prop) { ...@@ -53,23 +53,6 @@ async function getComputed(browser, id, prop) {
return null return null
} }
async function getComputedStyle(browser, id, prop) {
const val = await browser.eval(
`window.getComputedStyle(document.getElementById('${id}')).${prop}`
)
if (typeof val === 'number') {
return val
}
if (typeof val === 'string') {
const v = parseInt(val, 10)
if (isNaN(v)) {
return val
}
return v
}
return null
}
async function getSrc(browser, id) { async function getSrc(browser, id) {
const src = await browser.elementById(id).getAttribute('src') const src = await browser.elementById(id).getAttribute('src')
if (src) { if (src) {
...@@ -505,44 +488,6 @@ function runTests(mode) { ...@@ -505,44 +488,6 @@ function runTests(mode) {
}) })
} }
it('should correctly inherit the visibilty of the parent component', async () => {
let browser
try {
browser = await webdriver(appPort, '/hidden-parent')
const id = 'hidden-image'
// Wait for image to load:
await check(async () => {
const result = await browser.eval(
`document.getElementById(${JSON.stringify(id)}).naturalWidth`
)
if (result < 1) {
throw new Error('Image not ready')
}
return 'result-correct'
}, /result-correct/)
await waitFor(1000)
const desiredVisibilty = await getComputed(
browser,
id,
'style.visibility'
)
expect(desiredVisibilty).toBe('inherit')
const actualVisibility = await getComputedStyle(browser, id, 'visibility')
expect(actualVisibility).toBe('hidden')
} finally {
if (browser) {
await browser.close()
}
}
})
it('should correctly ignore prose styles', async () => { it('should correctly ignore prose styles', async () => {
let browser let browser
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment